Interface IHeadlessWebRuntime
interface IHeadlessWebRuntime
Extends com.amazon.apmf.IStandard
IHeadlessWebRuntime Interface
The IHeadlessWebRuntime interface provides a structured web framework for loading, and
interacting with web content within an application. It enables seamless integration
between an embedded web content and application layer, allowing for navigation, JavaScript execution,
and data exchange through a native-to-JavaScript bridge. This interface supports loading both web
pages and local resources.
With IHeadlessWebRuntime, developers can execute JavaScript in the context of the HeadlessWebRuntime and
handle callback results directly in caller context. Additionally, it facilitates the addition
of native functions accessible to JavaScript, allowing for data exchange and
interaction between web and native components. The interface includes client callbacks
for tracking the state of page loading, managing errors, and handling web request overrides.
Consumer should invoke these API’s in the application main thread.
Methods
navigateToUrl()
Loads web content referenced by url and navigates to it. URL can be http/https or file based local URLs.voidnavigateToUrl(stringurl)
Parameters
url
string — Required
URL to be loaded
navigateToUrlWithHeaders()
Loads web content referenced by url with additional headers.voidnavigateToUrlWithHeaders(stringurl,HttpHeader*[]?httpHeaders)
Parameters
url
string — Required
URL to be loaded
httpHeaders
HttpHeader*[]? — Optional
Extra HTTP headers to pass in load request
evaluateJavaScript()
Evaluate / executes the given JavaScript in the context of current HeadlessWebRuntime instance. This is useful when clients want to execute/inject custom JavaScript in the current HeadlessWebRuntime / JS context.voidevaluateJavaScript(stringJavaScriptCode,IEvaluateJavaScriptCallback?callback)
Parameters
JavaScriptCode
string — Required
JavaScript code to be executed.
callback
IEvaluateJavaScriptCallback? — Optional
Callback that will be invoked when the JavaScript result is available.
addJavaScriptInterface()
Adds native function(s) into JavaScript context with the specified scope and JsInterface . Note that function(s) are injected into all frames of the webpage. JavaScript code can invoke the native function synchronously after the web page loaded/re-loaded. This is useful in the scenarios where JavaScript code would like to invoke native code to pass the data between JavaScript and native layer. This API can also be mis-used if its not written properly. For example, third-party JavaScript libraries that you are using in your web app can access the injected function, so do not expose any sensitive/critical data or capabilities/actions using this API. Ex: In native code …voidaddJavaScriptInterface(stringscope,JsInterface*[]JsInterface)
Parameters
scope
string — Required
unique alias to the group of functions.
JsInterface
JsInterface*[] — Required
Array of [JsInterface] objects.
removeJavaScriptInterface()
Removes the JavaScript interface injected earlier by [IHeadlessWebRuntime#addJavaScriptInterface].voidremoveJavaScriptInterface(stringscope)
Parameters
scope
string — Required
unique alias to the group of functions.
setWebClient()
Sets the HeadlessWebRuntime Client object. Clients can receive notification about the HeadlessWebRuntime state changes. See @IWebClient interface for specific notifications, it includes page load start, page load completed, error, override web request etc.voidsetWebClient(IWebClient*webClient)
Parameters
webClient
IWebClient* — Required
WebClient callback object
clearWebClient()
void clearWebClient()
Clears the WebClient that was set earlier (if any).
getWebSettings()
Gets the HeadlessWebRuntime settings.IWebSettings*getWebSettings()
Returns
IWebSettings*
HeadlessWebRuntime Settings [IWebSettings]
setDevToolsEnabled()
Enable or disable the developer tools. Devtools can be used to debug/profile web content loaded in the application. Default is false. Note that this API affects all instances of [IHeadlessWebRuntime] running in the process. Its recommended not to enable this setting in the production version of application, as it exposes the state of web content through dev tools protocol.voidsetDevToolsEnabled(boolenable)
Parameters
enable
bool — Required
True to enable dev tools, False otherwise.

