Skip to content

[Breaking Change] Enabling WebView2 specific JavaScript API's for Service Workers #127

@Ju-MsGit

Description

@Ju-MsGit

[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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions