Repository navigation
fix(windows): prevent crash on WebView2 focus during dev hot-reload - #5315
Conversation
Two related issues during `wails3 dev` hot-reload on Windows: 1. SetProcessDpiAwarenessContext "Access is denied": the old guard used GetProcessDpiAwareness (SHCORE) to detect manifest-set DPI awareness, but this misses awareness set via SetProcessDpiAwarenessContext. Fix: prefer GetThreadDpiAwarenessContext (User32, Win10 1607+) which reflects both manifest and API-set contexts; fall back to SHCORE on older Windows. 2. [WebView2 Error] The parameter is incorrect / os.Exit(1): all four chromium.Focus() call sites in webview_window_windows.go now guard with GetController() != nil before calling into go-webview2. This prevents the fatal exit when the WebView2 controller is nil or torn down mid-lifecycle (e.g. during rapid process restarts in dev mode). Fixes: #4835 Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Co-authored-by: multica-agent <[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 (3)
WalkthroughThree modules are improved to prevent crashes during window operations: Windows API bindings for DPI awareness context detection are added, DPI setup now preempts redundant API calls, and WebView2 focus operations are guarded against a nil controller state. ChangesWebView2 Stability & DPI Awareness
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.11.4)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" 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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
Pull request overview
Fixes a Windows-only crash path during wails3 dev hot-reload by making DPI-awareness detection more reliable (avoiding SetProcessDpiAwarenessContext “access denied” when a manifest already set it) and by preventing fatal WebView2 focus calls when the controller is not available.
Changes:
- Add
GetThreadDpiAwarenessContext+AreDpiAwarenessContextsEqual(and feature-detection helpers) tow32and use them to detect manifest-set DPI awareness more reliably. - Update
setupDPIAwareness()to prefer thread DPI-awareness context checks before attempting to set process DPI awareness. - Guard all
chromium.Focus()call sites to avoid calling into go-webview2 when the controller isnil(preventingos.Exit(1)).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
v3/pkg/w32/user32.go |
Adds missing User32 bindings/helpers for thread DPI-awareness context inspection. |
v3/pkg/application/application_windows.go |
Uses the new DPI-awareness context APIs to skip SetProcessDpiAwarenessContext when already set via manifest. |
v3/pkg/application/webview_window_windows.go |
Adds controller-nil guards around WebView2 focus calls to avoid dev hot-reload crash. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… prevent crash on WebView2 focus during dev hot-reload
Fixes #4835
Summary
GetThreadDpiAwarenessContext+AreDpiAwarenessContextsEqualto w32; use them insetupDPIAwarenessto reliably detect permonitorv2 manifest-set DPI awareness before callingSetProcessDpiAwarenessContext.chromium.Focus()call sites withGetController() != nil. go-webview2 callsos.Exit(1)on any MoveFocus error, so calling Focus when the controller is nil or mid-init is fatal.Test plan
wails3 devon Windows 10/11: save a .go file, hot-reload must not crash?? Generated with Claude Code
Summary by CodeRabbit