Repository navigation
v3(windows): add WindowsOptions.UseVisualHosting to fix WebView2 hangs over RDP - #5380
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) <[email protected]>
|
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)
💤 Files with no reviewable changes (1)
WalkthroughThis PR adds a Windows WebView2 visual hosting option, wires it into startup initialization, and updates troubleshooting documentation and sidebar navigation for the related RDP guidance. ChangesWindows WebView2 Visual Hosting Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Thanks for the careful diagnosis and the doc references, @MerIijn — opt-in and default-off, so this is safe to land. Merging. |
Documents WindowsOptions.UseVisualHosting added in this PR: a Troubleshooting > Windows > RDP Issues page explaining the WebView2 DPI-context hang over Remote Desktop and the visual-hosting fix. Switches the Troubleshooting sidebar to explicit items so the Windows subgroup renders with a proper label.
…owsOptions.UseVisualHosting to fix WebView2 hangs over RDP
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
UseVisualHosting) to force WebView2 into Visual hosting mode, helping address RDP-related hangs when DPI changes occur mid-session.