Set the initial focus to WebView
To set the focus to WebView, do the following. In the src/App.tsx file, set the initial focus by adding thehasTVPreferredFocus={true} prop to the WebView component.
Send and receive messages from WebView pages
You can send and receive messages with WebView for Vega. To send and receive messages, use the following options:- React Native for Vega -> Web: The
injectJavaScriptmethod. - Web -> React Native for Vega: The
onMessageprop.
Implement Vega device Fire TV features from a web page
Thewindow.ReactNativeWebView.postMessage method runs the onMessage prop in React Native for Vega, which you can use to trigger Vega device Fire TV features. window.ReactNativeWebView.postMessage only accepts one argument, which must be a string.
Checking HDR format and codec support in WebView for Vega
WebView currently supports HEVC Main10 (HLG, HDR10, HDR10+) and VP9 Profile2 (HLG, HDR10) on the current Fire TV device. Current Fire TV devices don’t yet support AV1 HDR. Don’t use H264 and VP8 codecs for HDR. Check for HDR availability by usingcanPlayType() or isTypeSupported().
Enable back-button remote key events in web JavaScript
TheallowSystemKeyEvents property controls whether the web app actively listens for specific system key events, such as the back button (identified by keyCode: 27).
To enable back-button remote key events, do the following.
- In the src/App.tsx file, set the
allowSystemKeyEventsproperty totrue.
Enable and use DevTools for debugging
Chrome DevTools is enabled by default when you build the app with the debug version (process.env.NODE_ENV = 'development').
To build the DevTools debug app, do the following.
-
At the command prompt, run the following command.
- Install and launch the debug app, which opens a WebView.
-
Perform port forwarding at the command prompt by running the following command.
- Open Google Chrome, and then navigate to chrome://inspect/#devices.
- Find DevTools in the Remote Target section, in the list of connected devices.
- Open DevTools, by selecting inspect, and inspect the WebView.
Supported remote key events
The following table shows the supported remote key events and their associated key codes.Example checking for HDR using canPlayType()
Example checking for HDR using isTypeSupported()
MediaCapabilities.decodingInfo() because there are known issues. It reports VP9 Profile 2 support as false.
Example using HEVC
How to override default media control handlers
Some apps require granular control over media playback beyond what the default WebView media controls offer. Here are some examples.- Disabling seek operation during advertisements.
- Disabling all media control during live playback.
- Web-based implementation using
navigator.mediaSession. For this implementation, enableallowsDefaultMediaControlfor these reasons.- It enables transport control for play, pause, skip forward, and skip backward.
- It works directly in the web page without app code changes.
- Direct integration with the
VegaMediaControlinterface in your app code. For this integration, disableallowsDefaultMediaControlfor these reasons.- It provides full access to the device’s media control capabilities.
- It’s recommended for apps requiring deep system integration.
Web-based implementation using navigator.mediaSession
Thenavigator.mediaSession property is a web standard that provides a powerful interface between webpage media content and the device media control system. It enables web apps to register action handlers for media controls for the currently playing media, and customize how media controls behave across different content.
When allowsDefaultMediaControl is set to true in WebView, system-level controls like Alexa voice commands pass to registered custom handlers if available. Without registered handlers, WebView reverts to its default implementation. Custom handler use can then be based on playback context such as during advertisements or live streams.
For example, when users say, “Alexa, fast forward” with allowsDefaultMediaControl set to true, WebView passes the command to the web page’s seekforward handler if it’s registered. If the developer doesn’t register a handler, WebView falls back to its default seek implementation. This feature lets the web page control seeking behavior based on the content playing, such as blocking seeks during advertisements.
Example using navigator.mediaSession
Integration with VegaMediaControl interface in app
VegaMediaControl provides an interface for managing media playback in Vega apps. This direct integration enables granular control over media features such as playback controls, and seeking operations.
To integrate your Vega Web App with VegaMediaControl, follow these key steps:
-
Configure the WebView Prop.
- The default media control in WebView is disabled by default. To keep the controls disabled, either leave the prop unset or explicitly set
allowsDefaultMediaControltofalse. To use theVegaMediaControlintegration, keep the default media control disabled.
- The default media control in WebView is disabled by default. To keep the controls disabled, either leave the prop unset or explicitly set
-
Implement the
VegaMediaControlInterface.- Add
VegaMediaControlintegration to your app
- Add
-
JavaScript Bridge Communication
- Use
injectJavaScriptto control the web player according toVegaMediaControlhandlers.
- Use
Example integrating VegaMediaControl in your app code
The following is a detailed example demonstrating how to handle pause, play, seek forward, and seek backward commands. All of these commands useVegaMediaControl in your Vega Web App.
-
Add support for
VegaMediaControlin manifest.toml. Update the manifest for KMC, along with other entries. -
Add the following dependencies to package.json.
-
The following app code example creates the KMC server and the associated handler. Those handlers can inject JavaScript into the webpage with custom behavior.
Load a local file URL stored on the device into a WebView
By default, WebView loads apps from the /pkg/assets directory. However, you must set a property totrue if you want to load an app file from a different directory.
To load a local app file URL stored on the device, do the following.
- In the src/App.tsx, set the
allowFileAccessproperty totrue.
true enables WebView access and the ability to display the app file from the chosen directory. Failure to set allowFileAccess to true when you try to load an app file from a different directory causes an “Access Denied” error.
The file app functions within a sandboxed environment, limiting its access to the device’s file system. See the directories that the file app can access in the following table.
Example: Use WebView to load an HTML file from the assets directory
Example: Use WebView to load an HTML file from the app data directory
D-Pad navigation in WebView
WebView has spatial navigation enabled by default to provide basic D-Pad navigation.Prevent spatial navigation in WebView
For apps that implement custom focus management rather than the default spatial navigation focus, apps can useEvent::preventDefault when catching the keydown event. Using Event::preventDefault prevents conflicts between the custom focus logic and built-in WebView spatial navigation.
To manage serialized cookies or to clear cookies for your app, see Vega Web App Cookie Manager. To view other WebView APIs, see Vega Web App Component Reference.
How to prevent a flashing white screen before the page loads
Before loading a webpage, the view uses the component’s background color. If you don’t set the background color, then WebView chooses a white background. To change the background color, update thebackgroundColor style of the WebView component.
How to remove the remote playback icon at the top of the video playback screen
If WebView displays an icon at the top of the screen, thedisableRemotePlayback property may have caused it. Remove the icon by setting the property to true. A true property means it’s disabled, while false means it remains enabled.
Here’s an example:
How to selectively allow or block HTTP
Starting with WebView version 4.0.2 (RN 0.83), WebView prevents apps from loading plain-text (HTTP) URLs due to security concerns. However, there are some use-cases where app developers may need to load plain-text URLs. Apps can be configured to allow or block domains in their app manifest file.How it works
If nonetwork-traffic-policy.cleartext section is present in the manifest, all HTTP requests are blocked. Only HTTPS URLs load. This change applies beginning with WebView 4.0.2 (RN 0.83). Apps on WebView 3.5.11 (RN 0.72) or lower versions aren’t affected. When both allowed-domains and blocked-domains are specified, blocked-domains take priority.
Common use cases
-
Allow all HTTP except a few domains (blocklist).
Example: Allow cleartext for the whole application except sensitive domains.
-
Block all HTTP except specific domains (allowlist).
Example: Don’t enable cleartext for the whole application but trust specific domains.
-
Block all HTTP (no exceptions).
Example: Don’t allow cleartext at all.
-
Allow all HTTP (no restrictions).
Example: Allow cleartext for all domains. Perhaps for a captive portal app, or network diagnostics.

