[New API] AreWebViewScriptApisEnabledForServiceWorkers – WebView2 Service Worker JavaScript API exposure
Summary
WebView2 is introducing a new setting, AreWebViewScriptApisEnabledForServiceWorkers, to provide a reliable and explicit way to control the exposure of WebView2‑specific JavaScript APIs (chrome.webview) inside service worker scripts.
Details
Scope: WebView2
Purpose: Enable deterministic access to WebView2‑specific JavaScript APIs in service worker execution contexts.
The new API, AreWebViewScriptApisEnabledForServiceWorkers, determines whether WebView2‑specific JavaScript APIs are exposed to service worker scripts for a particular profile. When enabled, this setting allows developers to use WebView2's service worker postMessage APIs to communicate directly between service worker scripts and the WebView2 host application.
Behavior
Previously, the availability of WebView2‑specific JavaScript APIs (chrome.webview) in service worker scripts had no dedicated API to control it. The IsWebMessageEnabled setting only controlled whether postMessage calls were allowed but did not govern the exposure of the chrome.webview object itself in service worker script
|
IsWebMessageEnabled = true |
IsWebMessageEnabled = false |
AreWebViewScriptApisEnabledForServiceWorkers = true |
PostMessage API works |
PostMessage API doesn't work |
AreWebViewScriptApisEnabledForServiceWorkers = false |
PostMessage API doesn't work |
PostMessage API doesn't work |
Impact
Apps that rely on WebView2 service worker postMessage APIs without explicitly enabling JavaScript API exposure may encounter failures when attempting to communicate with service workers using WebView2's Service Worker postMessage APIs.
Rollout
This API is experimental in 146 pre-release, and starting with the 147 pre-release, this setting will solely determine the availability of the chrome and webview objects in WebView2 service worker scripts. Chrome and webview will continue to be available for apps using ServiceWorkerRegistered until 146; after 146, AreWebViewScriptApisEnabledForServiceWorkers must be enabled to expose them.
Testing
Enable the AreWebViewScriptApisEnabledForServiceWorkers setting and validate that service worker scripts can successfully access chrome.webview APIs and exchange messages with the host application.
Known Changes
- WebView2‑specific JavaScript APIs are exposed to service worker scripts only when the setting is enabled.
- No change to main document or non‑WebView2 service worker behavior.
App Action
Start using the AreWebViewScriptApisEnabledForServiceWorkers API to explicitly enable WebView2 JavaScript APIs for service worker scripts when your app requires service worker postMessage communication.
Timeline
-
Feature Enablement: chrome and webview will be available in service worker scripts for apps using ServiceWorkerRegistered. After 147 pre-release, AreWebViewScriptApisEnabledForServiceWorkers should be enabled to expose chrome and WebView in service worker script.
-
Testing Deadline: Apps are encouraged to complete their testing before 147 prelease (17th March 2026).
-
Contact: For questions or concerns, please use the WebView2Feedback repo.
[New API]
AreWebViewScriptApisEnabledForServiceWorkers– WebView2 Service Worker JavaScript API exposureSummary
WebView2 is introducing a new setting,
AreWebViewScriptApisEnabledForServiceWorkers, to provide a reliable and explicit way to control the exposure of WebView2‑specific JavaScript APIs (chrome.webview) inside service worker scripts.Details
Scope: WebView2
Purpose: Enable deterministic access to WebView2‑specific JavaScript APIs in service worker execution contexts.
The new API,
AreWebViewScriptApisEnabledForServiceWorkers, determines whether WebView2‑specific JavaScript APIs are exposed to service worker scripts for a particular profile. When enabled, this setting allows developers to use WebView2's service workerpostMessageAPIs to communicate directly between service worker scripts and the WebView2 host application.Behavior
Previously, the availability of WebView2‑specific JavaScript APIs (
chrome.webview) in service worker scripts had no dedicated API to control it. TheIsWebMessageEnabledsetting only controlled whetherpostMessagecalls were allowed but did not govern the exposure of thechrome.webviewobject itself in service worker scriptIsWebMessageEnabled = trueIsWebMessageEnabled = falseAreWebViewScriptApisEnabledForServiceWorkers = truePostMessageAPI worksPostMessageAPI doesn't workAreWebViewScriptApisEnabledForServiceWorkers = falsePostMessageAPI doesn't workPostMessageAPI doesn't workImpact
Apps that rely on WebView2 service worker
postMessageAPIs without explicitly enabling JavaScript API exposure may encounter failures when attempting to communicate with service workers using WebView2's Service WorkerpostMessageAPIs.Rollout
This API is experimental in 146 pre-release, and starting with the 147 pre-release, this setting will solely determine the availability of the
chromeandwebviewobjects in WebView2 service worker scripts.Chromeandwebviewwill continue to be available for apps usingServiceWorkerRegistereduntil 146; after 146,AreWebViewScriptApisEnabledForServiceWorkersmust be enabled to expose them.Testing
Enable the
AreWebViewScriptApisEnabledForServiceWorkerssetting and validate that service worker scripts can successfully accesschrome.webviewAPIs and exchange messages with the host application.Known Changes
App Action
Start using the
AreWebViewScriptApisEnabledForServiceWorkersAPI to explicitly enable WebView2 JavaScript APIs for service worker scripts when your app requires service workerpostMessagecommunication.Timeline
Feature Enablement:
chromeandwebviewwill be available in service worker scripts for apps using ServiceWorkerRegistered. After 147 pre-release,AreWebViewScriptApisEnabledForServiceWorkersshould be enabled to expose chrome and WebView in service worker script.Testing Deadline: Apps are encouraged to complete their testing before 147 prelease (17th March 2026).
Contact: For questions or concerns, please use the WebView2Feedback repo.