Web.h – Web class

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

FeatureCEFWebViewWeb Page (JS)Web.cpp (Suggested Names)
Page LoadedOnLoadEndWebViewClient.onPageFinishedwindow.onload / document.onreadystatechangeOnLoadEnd
Title ChangedOnTitleChangeWebChromeClient.onReceivedTitledocument.title + MutationObserverOnTitleChange
Icon Changed (Favicon)(Custom via resource request)WebChromeClient.onReceivedIcon<link rel="icon"> + MutationObserverOnIconChange
URL Changed / NavigatedOnAddressChangeWebViewClient.onPageStartedwindow.onpopstate / hashchangeOnAddressChange
Web Resource RequestedOnBeforeResourceLoadshouldInterceptRequestfetch / XMLHttpRequest overridesOnBeforeResourceLoad
Load ErrorOnLoadErrorWebViewClient.onReceivedErrorwindow.onerrorOnLoadError

Additional Web Page Lifecycle Events

FeatureCEFWebViewWeb Page (JS)Web.cpp (Suggested Names)
DOM Content LoadedOnLoadEnd (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 / RenderNot directly exposedNot exposedPerformancePaintTiming (needs PerformanceObserver)OnFirstRender
Page Fully RenderedNot directly exposedNot exposedApprox: requestIdleCallback or custom markerOnPageRendered
JS Runtime ReadyAfter browser initAfter WebView initWhen JS engine ready, e.g., via injected scriptOnWarpEngineReady
Before Unload / ExitOnBeforeCloseNot directly exposedwindow.onbeforeunloadOnBeforeUnload

Methods

FeatureCEFWebViewWeb Page (JS)Web.cpp (Suggested Names)
Navigate to URLbrowser->GetMainFrame()->LoadURL(url)loadUrl(url)window.location = url;Navigate(String url)
Go Backbrowser->GoBack()goBack()history.back()Back()
Go Forwardbrowser->GoForward()goForward()history.forward()Forward()
Reloadbrowser->Reload()reload()location.reload()Reload()
Stop Loadingbrowser->StopLoad()stopLoading()window.stop()Stop()
Evaluate JSbrowser->GetMainFrame()->ExecuteJavaScriptevaluateJavascript()<script> or eval()Eval(String js)
Get Page SourceGetSource()(Custom via evaluateJavascript)document.documentElement.outerHTMLSource()
Map a folder to a virtual host nameMapHost(
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