v3(windows): add WindowsOptions.UseVisualHosting to fix WebView2 hangs over RDP#5380
v3(windows): add WindowsOptions.UseVisualHosting to fix WebView2 hangs over RDP#5380MerIijn wants to merge 1 commit into
Conversation
…s over RDP When a Wails3 app is used over Microsoft Remote Desktop's iOS client (or any RDP client that provisions a virtual monitor with a different DPI context mid-session), WebView2's default windowed hosting forces a synchronous DComp re-marshal on every controller call. Each PutIsVisible, MoveFocus, first-paint, and surface release blocks the UI thread for ~2 s, and the bad state persists across reconnects until the host is rebooted. The aggregated cost on a typical popup-heavy app is 4-8 s for open and 2-3 s of parent-window stalls on close. A native Win32 + WebView2 sample on the same machine is unaffected, which is consistent with this being a hosting-mode interaction rather than a generic WebView2 or DWM bug. The Microsoft-documented fix is to set the COREWEBVIEW2_FORCED_HOSTING_MODE env var to COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL before WebView2 initialises. With visual hosting the controller's compositor surface is owned through a DComp visual the host owns, so DPI-context changes don't trigger the synchronous re-marshal. This change adds a WindowsOptions.UseVisualHosting opt-in (default false to preserve existing behavior) that sets the env var inside newPlatformApp, before any WebView2 environment is constructed. Refs: - https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/windowed-vs-visual-hosting - MicrosoftEdge/WebView2Feedback#5248 - MicrosoftEdge/WebView2Feedback#4485 - MicrosoftEdge/WebView2Feedback#1212 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis PR introduces a Windows-specific configuration option that allows applications to control WebView2's hosting mode. A new ChangesWindows WebView2 Visual Hosting Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.1)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
When a Wails3 app is used over Microsoft Remote Desktop's iOS client (or any RDP client that provisions a virtual monitor with a different DPI context mid-session), WebView2's default windowed hosting forces a synchronous DComp re-marshal on every controller call. Each
PutIsVisible,MoveFocus, first-paint, and surface release blocks the UI thread for ~2 s, and the bad state persists across reconnects until the host is rebooted. On a typical popup-heavy app this is 4-8 s per popup open and 2-3 s of parent-window stall on close.A native Win32 + WebView2 sample on the same machine is unaffected, which is consistent with this being a hosting-mode interaction rather than a generic WebView2 or DWM bug.
Fix
Microsoft documents
COREWEBVIEW2_FORCED_HOSTING_MODE_WINDOW_TO_VISUALas the workaround for "monitor-scale changes can cause hangs." With visual hosting the controller's compositor surface is owned through a DComp visual the host owns, so DPI-context changes don't trigger the synchronous re-marshal.This PR adds an opt-in
WindowsOptions.UseVisualHostingfield. When set,newPlatformAppsets theCOREWEBVIEW2_FORCED_HOSTING_MODEenv var before any WebView2 environment is initialised.Default is
falseto preserve existing behavior - windowed hosting remains the default and no apps see a behavior change unless they opt in.Usage
Verification
Confirmed in the iPhone-RDP-poisoned graphics state on Windows Server 2025 that:
The fix is identical to what the Microsoft Win32_GettingStarted sample relies on implicitly, which is why that sample isn't affected by the same RDP graphics state.
References
Tested on
Summary by CodeRabbit