react-native-webview, and it currently only supports a limited set of APIs.
To set up to use WebView, see Overview of Vega Web Apps.
Props
source
Loads the given URI with optional headers. The source object has the following sub properties.uri(string): The URI to load on the WebView.headers(object): Additional HTTP headers to send with the request.
onLoad
After WebView loads the web page, it callsonLoad.
Here is an example.
onLoad function pass the following properties:
onLoadStart
When WebView starts loading resources, it callsonLoadStart.
Here is an example.
onLoadStart pass the following properties.
onError
When the WebView fails to load the API callsonError.
Here is an example.
onError function pass the following properties.
onHttpError
When WebView fails to load it throws anonHttpError HTTP status error and the API calls the onHttpError function.
Any statusCodes >= 400 is an HTTP status error.
The isMainFrame flag identifies whether an error occurred when loading the main page, or a dependent resource. This will be true for main frame and false for subresources or iframes.
onHttpError function pass the following properties.
onCloseWindow
This function notifies the host app to close the given WebView and remove it from the view system. Since any WebView interaction after this call might result in unexpected behavior, the host app should destroy the WebView instance after receiving this call. There is no default functionality for this method.onMessage
Invoked when the WebView JS callsReactNativeWebView.postMessage. It accepts one argument and is available to the event object. The data must be a string.
Here is an example.
onShouldStartLoadWithRequest
onShouldStartLoadWithRequest allows custom handling of any WebView requests. A return of true continues loading the request, and false stops loading.
Here is an example.
onShouldStartLoadWithRequest object can contain the following properties.
onClientCertAuthentication (optional)
This optional function enables a host app to manage client certificate authentication requests.Parameters
- This gives you the details of the authentication request.
- This callback object has a function to handle authentication.
Callback Functions
- This function handles the client certificate authentication when the certificate is in PKCS#12 format.
- This function cancels the client certificate authentication process.
hostName- The server’s host name.portNumber- The port number for the request.
onSslError (optional)
This optional function notifies the host app that an SSL error occurred when it was loading a resource. The host app must call eitherSslErrorHandler.cancel() or SslErrorHandler.proceed(). By default, it rejects when an SSL error occurs when loading the URL.
Users can call the proceed() or cancel() methods to respond to future SSL errors. By default one of these functions cancels the resource loading process. WebView calls this function only for recoverable SSL certificate errors, such as untrusted certifier, certificate expiration, or self-signed. For non-recoverable errors, such as when the server fails the client, WebView calls onError(WebView, WebResourceRequest, WebResourceError) with the ERROR_FAILED_SSL_HANDSHAKE (-11) argument.
Here is an example.
SslErrorData objects
TheSslErrorData object contains the following properties:
urlcodedescription
OnSslErrorCallback object contains the following methods:
proceed()allows an SSL error.cancel()Rejects an SSL error.
javaScriptEnabled
A Boolean value to enable or disable JavaScript in WebView. The default value istrue.
Here is an example.
allowJavaScriptInBackground
A boolean value to enable JavaScript when the WebView app is in the background. The default isfalse.
Here is an example.
domStorageEnabled
A Boolean value to enable or disable DOM Storage (local web storage) in WebView. The default isfalse.
Here is an example.
userAgent
Setsuser-Agent for WebView.
Here is an example.
mixedContentMode
Specifies mixed content mode for the WebView. Here is an example.mixedContentMode are the following.
- Never (default), which uses
MIXED_CONTENT_NEVER_ALLOWWebView doesn’t allow a secure origin to load content from an insecure origin. Consider this mode because it is the most secure. - Always, which uses
MIXED_CONTENT_ALWAYS_ALLOW. WebView allows a secure origin to load content from any other origin, even if that origin is insecure. Amazon doesn’t recommend this because it is the least secure. - Compatibility, which uses
MIXED_CONTENT_COMPATIBILITY_MODE. WebView attempts to be compatible with the approach used by a modern web browser with regard to mixed content. WebView might allow some insecure content from a secure origin and when other types of content are blocked. The types of content that WebView allows or blocks might change release to release and are not explicitly defined. This mode is intended for apps that don’t control their own rendered content but require some reasonable security. For the highest security, useMIXED_CONTENT_NEVER_ALLOW.
allowFileAccess
A Boolean value to enable or disable access to the file system using file:// URI’s. The default value isfalse.
Here is an example.
allowSystemKeyEvents
A boolean that determines whether web app listens for special system key events like the Back button (keyCode: 27) in the Web JavaScript layer. This functionality helps web app developers who want to keep their business logic fully on the website instead of relying on the app code. The app can have its own back handlers, when allowSystemKeyEvents is true, and the event will be propagated based on the order components register their back handler (WebView/Application handlers). This will make sure that system key events are handled appropriately for the WebView content while providing application-level control.
Key considerations:
- Once WebView receives the back key event, it always consumes the event. It does not propagate to other remaining back handlers (if any), even if the app’s JavaScript does not consume the key event.
- In multiple WebView scenario(s), only the last created WebView instance gets back key events.
mediaPlaybackRequiresUserAction
A Boolean value to determine whether HTML5 audio and video requires a user to gesture before it starts playing. The default value istrue.
Here is an example.
thirdPartyCookiesEnabled
A Boolean value to enable or disable developer cookies in WebView. The default isfalse.
Here is an example.
allowsDefaultMediaControl
Allows theVegaMediaControl events to be automatically bridged to the active WebView media session. This allows seamless integration of voice commands for the WebView. For more details, see Vega Media Controls Overview.
trueenables the default media transport controls for the WebView media session, such as play, pause, seek forward, seek backward.falsedisables the default media transport controls.
- This setting affects all media content types including advertisements and live streams.
- For granular control over media content, see Overriding default media control handlers.
injectedJavaScriptBeforeContentLoaded
SetinjectedJavaScriptBeforeContentLoaded to inject JavaScript into a web page after the document element is created, but before other subresources finish loading. This is useful to inject anything into the window, localStorage, or document prior to web code execution.
Here’s an example:
Methods
injectJavaScript
injectJavaScript evaluates the JavaScript string in WebView.
Here is an example.
stopLoading
This stops loading the current page. Here is an example.clearCache(bool)
Clears the resource cache. The cache is per app, soclearCache clears the cache for all WebView parts of the same app. If the argument is true, it includes disk files. If the argument is false, it clears only the RAM cache.
Here is an example.
goBack()
Goes back one page in the WebView history. If there are no items in the history, this function performs no operations (no-op), and returns. Here is an example.goForward()
Goes forward one page in the WebView history. If there are no items in the history to go forward, this function performs no operations (no-op), and returns. Here is an example.clearHistory()
Clears the internal back/forward history for the WebView instance. Here is an example.dispatchTouchEvent(event: TouchEvent)
Dispatches a touch event to the specified target web element. It allows you to programmatically raise touch events such astouchstart and touchend.
Parameters
event: A TouchEvent object representing dispatched touch. This object contains information about the type of touch event (type) and an array of touch points associated with the event (touches).
Here is an example.
scrollBy(offsetX: number, offsetY: number)
Scrolls the content of the WebView by the specified offset values. This method allows you to programmatically scroll the content of the WebView by a specified horizontal (offsetX) and vertical (offsetY) offset.
Parameters
offsetX: A number representing the horizontal offset by which to scroll the content. A positive value scrolls the content to the right. A negative value scrolls it to the left.offsetY: A number representing the vertical offset by which to scroll the content. A positive value scrolls the content downwards. A negative value scrolls it upwards.
getVisualViewportInfo()
Retrieves information about the visual viewport of the WebView.Returns
An object containing information about the visual viewport, including:height: The height of the visual viewport.width: The width of the visual viewport.offsetTop: The offset from the top of the visual viewport to the top of the content.offsetLeft: The offset from the left of the visual viewport to the left of the content.
getContentSizeInfo()
Retrieves information about the size of the content within the WebView.Returns
An object containing information about the content size, including:scrollWidth: The total width of the content.scrollHeight: The total height of the content.

