API, a wrapper, for a web page.
Why our own :
- simplifies in code handling
- allows same API for, potentially, different rendering engines ( CEF, Webkit)
- without a layout engine it can serve as a stub/dummy for JS engine, triggering events downstream – that allow AI rendering on frontend
- implement MS WebView2 like, advanced, higher abstraction features which other wrappers ( webview.h) dont.
Mainly : virtual host mapping ( mapping https requests to a local folder making the Web instance a static https server ). This is OS independent and does not mess with the system’s hosts file (/etc/hosts on Linux and Mac, Windows\System32\drivers\etc\hosts on MS )
Events
Event naming and equivalents comparison table
Feature | CEF | WebView | Web Page (JS) | Web.cpp (Suggested Names) |
---|---|---|---|---|
Page Loaded | OnLoadEnd | WebViewClient.onPageFinished | window.onload / document.onreadystatechange |
|
Title Changed | OnTitleChange | WebChromeClient.onReceivedTitle | document.title + MutationObserver |
|
Icon Changed (Favicon) | (Custom via resource request) | WebChromeClient.onReceivedIcon | <link rel="icon"> + MutationObserver | OnIconChange |
URL Changed / Navigated | OnAddressChange | WebViewClient.onPageStarted | window.onpopstate / hashchange | OnAddressChange |
Web Resource Requested | OnBeforeResourceLoad | shouldInterceptRequest | fetch / XMLHttpRequest overrides |
|
Load Error | OnLoadError | WebViewClient.onReceivedError | window.onerror | OnLoadError |
Additional Web Page Lifecycle Events
Feature | CEF | WebView | Web Page (JS) | Web.cpp (Suggested Names) |
---|---|---|---|---|
DOM Content Loaded | OnLoadEnd (approximate) | WebViewClient.onPageFinished (approximate) | document.addEventListener("DOMContentLoaded") | OnDomReady |
All Scripts Loaded | (Custom via JS callback after load) | (Custom via JS or JS bridge) | window.onload or Promise.all([...scripts]) | OnScriptsLoaded |
First Paint / Render | Not directly exposed | Not exposed | PerformancePaintTiming (needs PerformanceObserver) | OnFirstRender |
Page Fully Rendered | Not directly exposed | Not exposed | Approx: requestIdleCallback or custom marker | OnPageRendered |
JS Runtime Ready | After browser init | After WebView init | When JS engine ready, e.g., via injected script | OnWarpEngineReady |
Before Unload / Exit | OnBeforeClose | Not directly exposed | window.onbeforeunload | OnBeforeUnload |
Methods
Feature | CEF | WebView | Web Page (JS) | Web.cpp (Suggested Names) |
---|---|---|---|---|
Navigate to URL | browser->GetMainFrame()->LoadURL(url) | loadUrl(url) | window.location = url; | Navigate(String url) |
Go Back | browser->GoBack() | goBack() | history.back() | Back() |
Go Forward | browser->GoForward() | goForward() | history.forward() | Forward() |
Reload | browser->Reload() | reload() | location.reload() | Reload() |
Stop Loading | browser->StopLoad() | stopLoading() | window.stop() | Stop() |
Evaluate JS | browser->GetMainFrame()->ExecuteJavaScript | evaluateJavascript() | <script> or eval() | Eval( |
Get Page Source | GetSource() | (Custom via evaluateJavascript ) | document.documentElement.outerHTML | Source() |
Map a folder to a virtual host name | – | – | – | MapHost( String path, String hostName, String protocol ) |
Additional methods
These public methods of Web.h are not pegged to a layout engine method
Agent, Title, Icon
(they set/get the Agent, title and favicon in the rendered web page)
X, Y, Width, Height
(position set/get in current window)
Visible, Opacity, Background, Alpha
( Background and alpha set colors (we need a color Struct) )
Win, Activate, Deactivate
(window related methods, Win return s the owner Win of the web )
Activate and deactivate should actually call owner Win methods for this)
Destroy