-
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
Open
chetanpandey1266
wants to merge
4
commits into
main
Choose a base branch
from
user/chetanpandey/ServiceWorkerSettingAPI
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Show resolved
Hide resolved
|
||
|
|
||
| if (webviewStagingSettings) | ||
| { | ||
| BOOL value; | ||
| webviewStagingSettings->get_IsServiceWorkerJSAPIsEnabled(&value); | ||
| CHECK_FAILURE(webviewStagingSettings->put_IsServiceWorkerJSAPIsEnabled(!value)); | ||
| MessageBox( | ||
| nullptr, | ||
| (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); | ||
| } | ||
| ``` | ||
|
|
||
| # API Details | ||
|
|
||
| ## Win32 C++ | ||
| ```cpp | ||
| /// A continuation of the ICoreWebView2Settings interface to manage Service Worker JS APIs. | ||
chetanpandey1266 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| interface ICoreWebView2StagingSettings : IUnknown { | ||
chetanpandey1266 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// 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.
Show resolved
Hide 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")] | ||
| { | ||
| Boolean IsServiceWorkerJSAPIsEnabled { get; set; }; | ||
chetanpandey1266 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.