Skip to content

Commit 2ea09d4

Browse files
authored
Update Freeze.md
1 parent dd74890 commit 2ea09d4

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

specs/Freeze.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ to access this feature so that invisible WebView can use less resources. We'd ap
44

55

66
# Description
7-
When a WebView in Win32 app becomes invisible, the app calls `TryFreeze` API so that it consumes less memory.
8-
For an Universal Windows Platform app, the app calls the API in suspended event handler before completing the suspended event.
7+
You may call the `TryFeezeAsync` API to have the WebView2 consume less memory. This is useful when your Win32 app becomes invisible, or when your Universal Windows Platform app is suspended, during the suspended event handler before completing the suspended event.
98

109
# Examples
1110
## .Net, WinRT
1211
```c#
1312
async protected void OnSuspending(object sender, SuspendingEventArgs args)
1413
{
1514
SuspendingDeferral deferral = args.SuspendingOperation.GetDeferral();
15+
// Set webView.Visibility to false first.
16+
// WebView2 must be invisible for TryFreezeAsync to succeed.
1617
webView.Visibility = false;
1718
await webView.CoreWebView2.TryFreezeAsync();
1819
deferral.Complete();
1920
}
2021
async protected void OnSuspending(object sender, Object args)
2122
{
23+
// Making a WebView2 visible will automatically unfreeze it
24+
// But you can also explicitly call Unfreeze without making a WebView2 visible to unfreeze it.
2225
webView.CoreWebView2.Unfreeze();
2326
webView.Visibility = true;
2427
}
@@ -75,18 +78,18 @@ void ViewComponent::Unfreeze()
7578
```
7679
7780
# Remarks
78-
WebView2 controller must be invisible when the API is called. Otherwise, the
81+
The CoreWebView2Controller must be invisible when the API is called. Otherwise, the
7982
API fails with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
80-
Freezing is similar to putting a tab into sleeping in browser. Freezing pauses
83+
Freezing is similar to putting a tab to sleep in the Edge browser. Freezing pauses
8184
WebView script timers and animations, minimizes CPU usage for the associated
8285
browser renderer process and allows the operating system to reuse the memory that was
8386
used by the renderer process for other processes.
8487
See [Sleeping Tabs FAQ](https://techcommunity.microsoft.com/t5/articles/sleeping-tabs-faq/m-p/1705434)
8588
for conditions that might prevent WebView from being frozen. In those situations,
86-
TryFreeze operation will fail and the completed handler will be invoked with isSuccessful as false.
87-
WebView will be automatically unfrozen when it becomes visible. Therefore, the app normally doesn't have to call Unfreeze.
88-
The app can call `Unfreeze` and then `TryFreeze` periodically for an invisibile WebView so that the WebView can sync up with
89-
latest data to show fresh content when it becomes visible.
89+
The TryFreeze operation will fail and the completed handler will be invoked with isSuccessful as false.
90+
The WebView will be automatically unfrozen when it becomes visible. Therefore, the app normally doesn't have to call Unfreeze.
91+
The app can call `Unfreeze` and then `TryFreeze` periodically for an invisibile WebView so that the invisible WebView can sync up with
92+
latest data and the page ready to show fresh content when it becomes visible.
9093
9194
# API Notes
9295
See [API Details](#api-details) section below for API reference.
@@ -97,8 +100,30 @@ See [API Details](#api-details) section below for API reference.
97100
```IDL
98101
interface ICoreWebView2_2 : ICoreWebView2 {
99102
103+
/// An app may call the `TryFeezeAsync` API to have the WebView2 consume less memory.
104+
/// This is useful when a Win32 app becomes invisible, or when a Universal Windows
105+
/// Platform app is suspended, during the suspended event handler before completing
106+
/// the suspended event.
107+
/// The CoreWebView2Controller must be invisible when the API is called. Otherwise, the
108+
/// API fails with `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`.
109+
/// Freezing is similar to putting a tab to sleep in the Edge browser. Freezing pauses
110+
/// WebView script timers and animations, minimizes CPU usage for the associated
111+
/// browser renderer process and allows the operating system to reuse the memory that was
112+
/// used by the renderer process for other processes.
113+
/// See [Sleeping Tabs FAQ](https://techcommunity.microsoft.com/t5/articles/sleeping-tabs-faq/m-p/1705434)
114+
/// for conditions that might prevent WebView from being frozen. In those situations,
115+
/// The TryFreeze operation will fail and the completed handler will be invoked with isSuccessful as false.
116+
/// The WebView will be automatically unfrozen when it becomes visible. Therefore, the
117+
/// app normally doesn't have to call Unfreeze.
118+
/// The app can call `Unfreeze` and then `TryFreeze` periodically for an invisibile WebView so that
119+
/// the invisible WebView can sync up with latest data and the page ready to show fresh content
120+
/// when it becomes visible.
100121
HRESULT TryFreeze([in] ICoreWebView2StagingTryFreezeCompletedHandler* handler);
101122
123+
/// Unfreeze the WebView so that it would resume activities on the web page.
124+
/// This API can be called while the WebView2 controller is invisible.
125+
/// The app can interact with the WebView immediately after unfreeze.
126+
/// WebView will be automatically unfrozen when it becomes visible.
102127
HRESULT Unfreeze();
103128
}
104129
@@ -117,7 +142,7 @@ namespace Microsoft.Web.WebView2.Core
117142
public partial class CoreWebView2
118143
{
119144
// There are other API in this interface that we are not showing
120-
public Task<int> TryFreezeAsync();
145+
public Task<bool> TryFreezeAsync();
121146
public void Unfreeze();
122147
}
123148
}

0 commit comments

Comments
 (0)