Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Get Started
Design and Develop
Publish
Reference
Support
Native
Skip to main content

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

void navigateToUrl(string url)
Loads web content referenced by url and navigates to it. URL can be http/https or file based local URLs.

Parameters

url
string — Required URL to be loaded
void navigateToUrlWithHeaders(string url, HttpHeader*[]? httpHeaders)
Loads web content referenced by url with additional headers.

Parameters

url
string — Required URL to be loaded
httpHeaders
HttpHeader*[]? — Optional Extra HTTP headers to pass in load request

evaluateJavaScript()

void evaluateJavaScript(string JavaScriptCode, IEvaluateJavaScriptCallback? callback)
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.

Parameters

JavaScriptCode
string — Required JavaScript code to be executed.
callback
IEvaluateJavaScriptCallback? — Optional Callback that will be invoked when the JavaScript result is available.

addJavaScriptInterface()

void addJavaScriptInterface(string scope, JsInterface*[] JsInterface)
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 …
… In JavaScript code
…

Parameters

scope
string — Required unique alias to the group of functions.
JsInterface
JsInterface*[] — Required Array of [JsInterface] objects.

removeJavaScriptInterface()

void removeJavaScriptInterface(string scope)
Removes the JavaScript interface injected earlier by [IHeadlessWebRuntime#addJavaScriptInterface].

Parameters

scope
string — Required unique alias to the group of functions.

setWebClient()

void setWebClient(IWebClient* webClient)
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.

Parameters

webClient
IWebClient* — Required WebClient callback object

clearWebClient()

void clearWebClient()
Clears the WebClient that was set earlier (if any).

getWebSettings()

IWebSettings* getWebSettings()
Gets the HeadlessWebRuntime settings.

Returns

IWebSettings* HeadlessWebRuntime Settings [IWebSettings]

setDevToolsEnabled()

void setDevToolsEnabled(bool enable)
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.

Parameters

enable
bool — Required True to enable dev tools, False otherwise.
Last modified on October 29, 2026