Skip to content

v3(windows): add WindowsOptions.UseVisualHosting to fix WebView2 hangs over RDP - #5380

Merged
leaanthony merged 5 commits into
wailsapp:masterfrom
MerIijn:fix/webview2-rdp-visual-hosting
Jun 29, 2026
Merged

leaanthony merged 5 commits into
wailsapp:masterfrom
MerIijn:fix/webview2-rdp-visual-hosting

Conversation

@MerIijn

@MerIijn MerIijn commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

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_VISUAL as 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.UseVisualHosting field. When set, newPlatformApp sets the COREWEBVIEW2_FORCED_HOSTING_MODE env var before any WebView2 environment is initialised.

Default is false to preserve existing behavior - windowed hosting remains the default and no apps see a behavior change unless they opt in.

Usage

app := application.New(application.Options{
    Windows: application.WindowsOptions{
        UseVisualHosting: true,
    },
})

Verification

Confirmed in the iPhone-RDP-poisoned graphics state on Windows Server 2025 that:

  • Before: every popup window 4-8 s click->content; close blocks parent UI ~2 s.
  • After: popups open within Chromium's normal navigation time (~150-500 ms); close does not block the parent window.

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

  • Windows Server 2025 Datacenter Evaluation (build 26100)
  • Wails v3 master (commit af4669e, v3.0.0-alpha.88)
  • WebView2 runtime 148.0.3967.54

Summary by CodeRabbit

  • New Features
    • Added a Windows setting (UseVisualHosting) to force WebView2 into Visual hosting mode, helping address RDP-related hangs when DPI changes occur mid-session.
  • Documentation
    • Updated troubleshooting documentation with a new RDP-focused page explaining the issue and how to enable the new option (configured before app startup).

…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]>
@coderabbitai

coderabbitai Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 67ea814c-d7e1-491d-927e-82ecff3ae0b6

📥 Commits

Reviewing files that changed from the base of the PR and between 628f184 and 373da5a.

📒 Files selected for processing (2)
  • docs/astro.config.mjs
  • docs/src/content/docs/troubleshooting/windows/rdp.mdx
💤 Files with no reviewable changes (1)
  • docs/src/content/docs/troubleshooting/windows/rdp.mdx

Walkthrough

This 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.

Changes

Windows WebView2 Visual Hosting Configuration

Layer / File(s) Summary
Configuration Option
v3/pkg/application/application_options.go
WindowsOptions gains the exported UseVisualHosting boolean field with documentation describing its effect on WebView2 hosting mode and the requirement to set it before app.Run().
Environment Setup
v3/pkg/application/application_windows.go
newPlatformApp conditionally sets COREWEBVIEW2_FORCED_HOSTING_MODE to COREWEBVIEW2_HOSTING_MODE_WINDOW_TO_VISUAL when UseVisualHosting is enabled, before DPI awareness and WebView2 initialization.
Troubleshooting Docs
docs/astro.config.mjs, docs/src/content/docs/troubleshooting/windows/rdp.mdx
The troubleshooting sidebar becomes explicit for Windows entries, and a new RDP page documents the issue, the visual hosting setting, usage guidance, and references.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

Windows, Enhancement, Documentation, v3-alpha, size:M

Suggested reviewers

  • leaanthony

Poem

🐰 A visual hop, a hosted gleam,
WebView2 now follows the chosen scheme.
One flag at dawn, before app.Run(),
And docs explain how the fix is done ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately summarizes the opt-in Windows visual-hosting fix.
Description check ✅ Passed The description covers the problem, fix, usage, verification, references, and testing details, with only the issue link and checklist left incomplete.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@taliesin-ai

Copy link
Copy Markdown
Collaborator

Thanks for the careful diagnosis and the doc references, @MerIijn — opt-in and default-off, so this is safe to land. Merging.

@taliesin-ai
taliesin-ai enabled auto-merge (squash) June 29, 2026 01:32
taliesin-ai and others added 3 commits June 29, 2026 11:47
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.
@leaanthony
leaanthony disabled auto-merge June 29, 2026 05:54
@leaanthony
leaanthony merged commit 7a4b93f into wailsapp:master Jun 29, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Wails Release Train Jun 29, 2026
leaanthony pushed a commit that referenced this pull request Jun 29, 2026
…owsOptions.UseVisualHosting to fix WebView2 hangs over RDP
@MerIijn
MerIijn deleted the fix/webview2-rdp-visual-hosting branch June 29, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants