-
Notifications
You must be signed in to change notification settings - Fork 64
API Review: Service Worker Post Message Setting #5465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
bc1a4f3
61ffa14
122a2ae
e45f66e
26f2ecd
10261a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| Service Worker PostMessage Setting | ||
| === | ||
| # Background | ||
|
|
||
| This API provides a setting to expose the webview2 specific JS APIs on service worker script. | ||
|
|
||
| # Description | ||
|
|
||
| We propose adding `ServiceWorkerJSAPIsEnabled` setting API as it allows developers to expose the webview2 specific JS APIs on service worker script. When enabled this would enable the developers to use webview2's service worker postmessage APIs to communicate directly between the service worker script and webview2 host. | ||
|
|
||
| # Examples | ||
|
|
||
| ## Win32 C++ | ||
|
|
||
| ```cpp | ||
| void ToggleServiceWorkerJsApiSetting() | ||
| { | ||
| wil::com_ptr<ICoreWebView2StagingSettings> webviewStagingSettings; | ||
| webviewStagingSettings = m_settings.try_query<ICoreWebView2StagingSettings>(); | ||
|
chetanpandey1266 marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (webviewStagingSettings) | ||
| { | ||
| BOOL value; | ||
| webviewStagingSettings->get_IsServiceWorkerJSAPIsEnabled(&value); | ||
| CHECK_FAILURE(webviewStagingSettings->put_IsServiceWorkerJSAPIsEnabled(!value)); | ||
| MessageBox( | ||
| nullptr, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix. |
||
| (std::wstring(L"Service Worker JS API setting has been ") + | ||
| (!value ? L"enabled." : L"disabled.")) | ||
| .c_str(), | ||
| L"Service Worker JS API Setting", MB_OK); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## C#/.NET | ||
|
|
||
| ```c# | ||
| private void ToggleServiceWorkerJsApiSetting() | ||
| { | ||
| WebViewSettings.IsServiceWorkerJSAPIsEnabled = !WebViewSettings.AreDefaultScriptDialogsEnabled; | ||
|
|
||
| MessageBox.Show(this, | ||
| $"IsServiceWorkerJSAPIsEnabled is now set to: {WebViewSettings.IsServiceWorkerJSAPIsEnabled}", | ||
| "Trusted Origins", MessageBoxButtons.OK, MessageBoxIcon.Information); | ||
| } | ||
|
david-risney marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| # API Details | ||
|
|
||
| ## Win32 C++ | ||
| ```cpp | ||
| /// A continuation of the ICoreWebView2Settings interface to manage Service Worker JS APIs. | ||
|
chetanpandey1266 marked this conversation as resolved.
Outdated
|
||
| interface ICoreWebView2StagingSettings : IUnknown { | ||
|
chetanpandey1266 marked this conversation as resolved.
Outdated
|
||
| /// Gets the `IsServiceWorkerJSAPIsEnabled` property. | ||
| [propget] HRESULT IsServiceWorkerJSAPIsEnabled([out, retval] BOOL* value); | ||
|
|
||
| /// Enables or disables webview2 specific Service Worker JS APIs in the WebView2. | ||
| /// When set to `TRUE`, chrome and webview objects are available in Service Workers . | ||
| /// chrome.webview exposes APIs to interact with the WebView from Service Workers. | ||
| /// The default value is `FALSE`. | ||
| /// When enabled, this setting takes effect for all the newly installed Service Workers. | ||
|
chetanpandey1266 marked this conversation as resolved.
|
||
| /// \snippet SettingsComponent.cpp ToggleServiceWorkerJSAPIsEnabled | ||
| [propput] HRESULT IsServiceWorkerJSAPIsEnabled([in] BOOL value); | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| ## .NET/C# | ||
| ```c# | ||
| namespace Microsoft.Web.WebView2.Core | ||
| { | ||
| runtimeclass CoreWebView2Settings | ||
| { | ||
| [interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2StagingSettings")] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Precedent is to increment a number suffix of the interface, for new properties on CoreWebView2Settings, rather than insert adjectives. (see ICoreWebView2Settings12 adding IsNonClientRegionSupportEnabled. If we haven't otherwise already changed patterns, stay consistent for new properties.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix like previous comment. |
||
| { | ||
| Boolean IsServiceWorkerJSAPIsEnabled { get; set; }; | ||
|
chetanpandey1266 marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| } | ||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.