Fix Cmd+W not working in PWA when bubble/overlay is focused

Commit: 40d0a114 | 2026-01-21 23:58:07+00:00

← Back to List

Fix Cmd+W not working in PWA when bubble/overlay is focused

Minor
Commit Hash: 40d0a114c5020ced4cd95d14de5751ed856f9ad2
Commit Time: 2026-01-21 23:58:07+00:00
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This commit fixes an issue in Mac PWAs where the Cmd+W keyboard shortcut does not close the window when a bubble (e.g., Cast dialog) has focus. The root cause is that bubble windows lack the NSWindowStyleMaskClosable style mask. The fix overrides the performClose: method in NativeWidgetMacNSWindow to forward the close action to the parent window when the child window lacks NSWindowStyleMaskClosable, thereby allowing Cmd+W to properly close the PWA main window. This change only affects the native_widget_mac_nswindow.mm file, adding 12 lines of code to implement this functionality.

🎯 Impact Analysis

This change has a **Minor to Moderate** impact on WebView2Mac. Detailed analysis follows:

**Direct Impact:**
1. **Inheritance Relationship**: WebView2Mac's HostingNSWindowBridge inherits from NativeWidgetNSWindowBridge, and the modification occurs in the NativeWidgetMacNSWindow class. Since WebView2Mac uses NativeWidgetMacNSWindow as its window base class, this change will automatically apply to all WebView2Mac window instances.

2. **Window Hierarchy Handling**: The new performClose: logic will affect the closing behavior of WebView2Mac's child windows (such as popups and dialogs). When these child windows lack NSWindowStyleMaskClosable and are focused, Cmd+W operations will be forwarded to the parent window.

**Potential Issues:**
1. **Host Application Integration**: A unique aspect of WebView2Mac is that its parent window is typically owned by the host application, not Chromium. If the host application's window handles performClose: differently than expected, it may lead to unexpected behavior.

2. **Behavior Changes**: For WebView2Mac child windows without NSWindowStyleMaskClosable (such as custom popups and toolbar windows), Cmd+W behavior will change from being unresponsive to attempting to close the parent window. This could affect user experience, especially when the parent window is the host application's main window.

**Positive Impact:**
1. **Consistency Improvement**: Unifies window closing shortcut behavior, ensuring all child windows properly respond to Cmd+W, improving user experience consistency.

2. **Code Simplicity**: This is a targeted fix with minimal code changes, making the risk relatively controllable.

**Recommendation:**
It is recommended to test various child windows used in WebView2Mac (especially those without NSWindowStyleMaskClosable) to ensure Cmd+W shortcut behavior meets expectations and does not inadvertently close the host application's window.

Impacted Classes:

NativeWidgetMacNSWindow remote_cocoa::NativeWidgetNSWindowBridge