-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Description
WebView2 leaks GDI objects when the mouse moves over its rendering surface. The leak occurs regardless of CSS, JavaScript, or host application behavior. Over time this exhausts the Windows per-process GDI limit (10,000), causing system-wide cursor stutter and UI lag.
Reproduction
- Create a WebView2 window (via WRY/Tauri, but likely reproducible with any host)
- Load a simple HTML page (static text is sufficient)
- Monitor GDI objects: `GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS)`
- Move the mouse over the WebView2 surface continuously
Result: GDI object count climbs ~2000+ per 30 seconds of mouse movement and never decreases.
Control: With the mouse stationary or outside the WebView2 window, GDI count is stable.
Evidence
Monitoring via PowerShell (`GetGuiResources` every 30 seconds):
Mouse hovering over static text in WebView2
```
12:26:36 | gdi=42
12:27:06 | gdi=2268 (+2226 in 30 seconds)
```
Mouse stationary (no interaction)
```
gdi stable at 30-36 for 30+ minutes
```
What we ruled out
Extensive testing ruled out application-side causes:
- Not CSS: Removed all `:hover` rules and `transition` properties — still leaks
- Not JavaScript: JS heap stable, DOM node count stable (47 nodes unchanged)
- Not the host app: Instrumented all Rust-side GDI operations (`GetIconInfo`, `GetDIBits`, `DeleteObject`) with `GetGuiResources` delta checks — zero delta from application code
- Not rendering count: Debouncing React re-renders from 4/event to 1/event had no effect
- `SetIsVisible(false/true)` makes it WORSE — toggling visibility causes even MORE GDI objects to leak (~6000 in 30 seconds vs ~2000 without toggling)
- `pointer-events: none` in CSS does not help — WebView2 still receives `WM_MOUSEMOVE` at the OS level
Impact
This particularly affects taskbar/widget-style applications where the WebView2 window sits at a screen edge and the mouse frequently crosses it. In our case (Zebar, a desktop widget app using Tauri/WRY), users experience cursor stutter and UAC dialog lag after 1-2 hours of normal use.
Environment
- Windows 11 (MSYS_NT-10.0-26200)
- WebView2 Runtime (latest stable)
- Tested via WRY 0.51.2 / Tauri 2.x
- Multiple WebView2 windows active
Additional context
Filed via investigation on: