WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: IME composition UI detaches to the screen top-left after switching between two WebView2 windows in the same process

Open TakahiroNago opened this issue 3 weeks ago • 1 comments

What happened?

Two WebView2 controls hosted in two top-level windows of the same process, sharing one user data folder (and therefore one browser process). After clicking back and forth between the two windows, typing with a CJK IME in one of them breaks:

  • The composition UI appears detached at the top-left of the screen. In the browser process (msedgewebview2.exe) an MSCTFIME Composition window and a CiceroUIWndFrame window are shown at about (0,0)-(56,31); the candidate UI ("Windows Input Experience") opens at (0,10).
  • The page never receives compositionstart; nothing is composed into the focused textarea. Plain ASCII typing still works.
  • Once a window is in this state it stays broken on every re-activation, while the other window keeps working. Which window breaks varies between runs. Waiting 1.5 s before typing does not help.

Reproduced with Microsoft Japanese IME and Microsoft Pinyin, with the attached minimal WinForms project (Microsoft.Web.WebView2 1.0.3719.77, net8.0-windows). An automated run of 20 alternating clicks (one IME key per visit) gives 10/20 failures: every visit to one of the two windows fails.

What makes it go away:

  • A separate user data folder per window (separate browser processes): 0/20.
  • Switching between windows of two different applications: 0/20.
  • In a Win32 host that calls ICoreWebView2Controller::MoveFocus(PROGRAMMATIC) synchronously inside the parent window's WM_SETFOCUS (which is effectively what the WinForms control does in OnGotFocus), posting a message and calling MoveFocus after the activation has completed reduces the failure rate from 10/20 to 0-1/20.

This suggests that calling MoveFocus while Windows is still processing the activation sequence leaves the TSF focus for that WebView's HWND associated with the wrong (default) document manager, so the IME falls back to the legacy composition window.

Not applicable to / not tested in the Edge browser: the scenario needs two hosted WebView2 controls.

Related: #5675 (composition UI at top-left after host resize), #1611, #5570 (same symptom, different triggers); original reports in tauri-apps/wry#1908 and tauri-apps/tauri#16391 (also on Runtime 142.0.3595.69).

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

157.0.4341.42

SDK Version

1.0.3719.77

Framework

Winforms

Operating System

Windows 11

OS Version

10.0.26200

Repro steps

  1. Build and run the attached WebView2TwoWindowsImeRepro project (dotnet build -c Release). Two windows A and B open, each with a