ICoreWebView2_3.TrySuspend

An app may call the TrySuspend API to have the WebView2 consume less memory. This is useful when a Win32 app becomes invisible, or when a Universal Windows Platform app is being suspended, during the suspended event handler before completing the suspended event. The CoreWebView2Controller's IsVisible property must be false when the API is called. Otherwise, the API fails with HRESULT_FROM_WIN32(ERROR_INVALID_STATE). Suspending is similar to putting a tab to sleep in the Edge browser. Suspending pauses WebView script timers and animations, minimizes CPU usage for the associated browser renderer process and allows the operating system to reuse the memory that was used by the renderer process for other processes. Note that Suspend is best effort and considered completed successfully once the request is sent to browser renderer process. If there is a running script, the script will continue to run and the renderer process will be suspended after that script is done. See Sleeping Tabs FAQ for conditions that might prevent WebView from being suspended. In those situations, the completed handler will be invoked with isSuccessful as false and errorCode as S_OK. The WebView will be automatically resumed when it becomes visible. Therefore, the app normally does not have to call Resume explicitly. The app can call Resume and then TrySuspend periodically for an invisible WebView so that the invisible WebView can sync up with latest data and the page ready to show fresh content when it becomes visible. All WebView APIs can still be accessed when a WebView is suspended. Some APIs like Navigate will auto resume the WebView. To avoid unexpected auto resume, check IsSuspended property before calling APIs that might change WebView state.

\snippet ViewComponent.cpp ToggleIsVisibleOnMinimize

\snippet ViewComponent.cpp Suspend

interface ICoreWebView2_3
HRESULT
TrySuspend

Meta