-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add Spec: Critical Restart Required #4657
base: main
Are you sure you want to change the base?
Changes from all commits
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,105 @@ | ||||||
Critical Update Available | ||||||
=== | ||||||
|
||||||
# Background | ||||||
As WebView2 developers, we often have to author ECS (experimentation and configuration service - | ||||||
used to perform A/B testing or remotely disable features) configurations to toggle feature flags. | ||||||
However, once these payloads are received, there is no way to restart the WebView2 and apply the | ||||||
payload. The purpose of this API is to detect such critical payloads and inform the end developer | ||||||
so they may restart their app or their WebView2 or other appropriate action. | ||||||
|
||||||
# Examples | ||||||
## WinRT and .NET | ||||||
```c# | ||||||
void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e) | ||||||
{ | ||||||
if (e.IsSuccess) | ||||||
{ | ||||||
// ... | ||||||
webView.CoreWebView2.Environment.CriticalRestartRequired += WebView_CriticalRestartRequired; | ||||||
} | ||||||
} | ||||||
|
||||||
void WebView_CriticalRestartRequired(object sender, object e) | ||||||
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.
Suggested change
|
||||||
{ | ||||||
// Depending on your app experience, you may or may not | ||||||
// want to prompt user to restart the app. | ||||||
RestartIfSelectedByUser(); | ||||||
} | ||||||
``` | ||||||
|
||||||
## Win32 C++ | ||||||
```cpp | ||||||
void CoreWebView2InitializationCompleted() { | ||||||
wil::com_ptr<ICoreWebView2Environment> m_webViewEnvironment; | ||||||
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. Declare this as a member variable rather than a local, and then the reader realizes that it's initialized somewhere out-of-scope to this example |
||||||
auto env10 = m_webViewEnvironment.try_query<ICoreWebView2Environment10>(); | ||||||
CHECK_FAILURE(env10->add_CriticalRestartRequired( | ||||||
Callback<ICoreWebView2CriticalRestartRequiredEventHandler>( | ||||||
[this](ICoreWebView2Environment* sender, IUnknown* args) -> HRESULT | ||||||
{ | ||||||
// Depending on your app experience, you may or may not | ||||||
// want to prompt user to restart the app. | ||||||
RestartIfSelectedByUser(); | ||||||
return S_OK; | ||||||
}) | ||||||
.Get(), | ||||||
nullptr)); | ||||||
} | ||||||
``` | ||||||
|
||||||
# API Notes | ||||||
|
||||||
See [API Details](#api-details) section below for API reference. | ||||||
|
||||||
# API Details | ||||||
## Win32 C++ | ||||||
|
||||||
```IDL | ||||||
interface ICoreWebView2Environment10; | ||||||
interface ICoreWebView2CriticalRestartRequiredEventHandler; | ||||||
|
||||||
[uuid(62cb67c6-b6a9-4209-8a12-72ca093b9547), object, pointer_default(unique)] | ||||||
interface ICoreWebView2CriticalRestartRequiredEventHandler : IUnknown { | ||||||
/// Provides the event args for the corresponding event. No event args exist | ||||||
/// and the `args` parameter is set to `null`. | ||||||
HRESULT Invoke([in] ICoreWebView2Environment* sender, [in] IUnknown* args); | ||||||
} | ||||||
|
||||||
[uuid(ef7632ec-d86e-46dd-9d59-e6ffb5c87878), object, pointer_default(unique)] | ||||||
interface ICoreWebView2Environment10 : IUnknown { | ||||||
/// Add an event handler for the `CriticalRestartRequired` event. | ||||||
/// `CriticalRestartRequired` event is raised when there is an urgent need to | ||||||
/// restart the WebView2 process in order to enable or disable | ||||||
/// features that are causing WebView2 reliability or performance to drop critically. | ||||||
/// `CriticalRestartRequired` gives you the awareness of these necessary WebView2 restarts, | ||||||
/// allowing you to resolve issues faster than waiting for your end users to restart the app. | ||||||
/// Depending on your app you may want to prompt your end users in some way to give | ||||||
/// them a chance to save their state before you restart the WebView2. | ||||||
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. Thank you, this is a great customer-focused API description :) |
||||||
/// | ||||||
/// For apps with multiple processes that host WebView2s that share the same user data folder you | ||||||
/// need to make sure all WebView2 instances are closed and the associated WebView2 Runtime | ||||||
/// browser process exits. See `BrowserProcessExited` for more details. | ||||||
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. If there's another app using WV2, but not the same UDF, then it won't cause a problem? |
||||||
// MSOWNERS: xiaqu@microsoft.com | ||||||
HRESULT add_CriticalRestartRequired( | ||||||
[in] ICoreWebView2CriticalRestartRequiredvEventHandler* eventHandler, | ||||||
[out] EventRegistrationToken* token); | ||||||
|
||||||
/// Remove an event handler previously added with `add_CriticalRestartRequired`. | ||||||
// MSOWNERS: xiaqu@microsoft.com | ||||||
HRESULT remove_CriticalRestartRequired( | ||||||
[in] EventRegistrationToken token); | ||||||
} | ||||||
``` | ||||||
s | ||||||
## .NET and WinRT | ||||||
|
||||||
```c# | ||||||
namespace Microsoft.Web.WebView2.Core | ||||||
{ | ||||||
runtimeclass CoreWebView2Environment | ||||||
{ | ||||||
// ... | ||||||
event Windows.Foundation.TypedEventHandler<CoreWebView2Environment, Object> CriticalRestartRequired; | ||||||
} | ||||||
} | ||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does "restart" mean e.g. AppInstance.Restart? Would help to show this in the example.
Is there a way to just restart the WV2 though?