feat(webview2): add with_native_window_occlusion option#1742
Open
podheitor wants to merge 1 commit into
Open
Conversation
Allow disabling WebView2's native window occlusion detection (CalculateNativeWinOcclusion) so a webview keeps rendering while its window is hidden or occluded. Webviews created while hidden otherwise may never bring up their render surface and paint blank when first shown, which breaks apps that pre-create and show/hide multiple webviews (tabbed/multi-service shells). Defaults to true (current WebView2 behavior); opt out via WebViewBuilderExtWindows::with_native_window_occlusion(false). Refs: tauri-apps/tauri#9798, MicrosoftEdge/WebView2Feedback#1077
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
feat(webview2): add
with_native_window_occlusionoptionWhat
Adds a Windows-specific builder option
WebViewBuilderExtWindows::with_native_window_occlusion(bool)that lets an app opt out of WebView2's native window occlusion detection.When set to
false, wry appendsCalculateNativeWinOcclusionto the--disable-featureslist it already passes by default. It defaults totrue, so current behavior is unchanged unless you explicitly opt out.Why
On Windows, WebView2 stops (or never starts) rendering a webview whose host window is hidden or fully occluded, to save resources. That's fine for a single foreground webview, but it breaks apps that pre-create several webviews and show/hide them on demand (tabbed browsers, multi-service messaging shells, etc.): a webview created while hidden may never bring up its render surface and paints blank the first time it's shown.
This is a long-standing pain point with no in-library workaround today:
WebviewWindowblankDisabling
CalculateNativeWinOcclusionis the documented lever for this, but the only way to reach it today iswith_additional_browser_args, which fully overrides wry's default args (the mini-menu / SmartScreen / autoplay / proxy flags) — so you lose all of those unless you reproduce them by hand. This option exposes just the occlusion toggle while keeping wry's defaults intact.How
native_window_occlusion: boolon the WindowsPlatformSpecificWebViewAttributes(defaults totrue).WebViewBuilderExtWindows.webview2/mod.rs, when the option isfalse, append,CalculateNativeWinOcclusionto the default--disable-featuresstring. No effect whenwith_additional_browser_argsis used (documented), since that path is a full override.Usage
Notes
#[cfg(windows)], like the otherWebViewBuilderExtWindowsoptions).x86_64-pc-windows-gnu.minor).Real-world validation: this is what made reliable multi-webview show/hide work in a Tauri app that pre-creates one hidden webview per service and swaps them — without it, the second-and-later webviews paint blank on first show.