Skip to content

fix(browser): stop Ctrl+W in the browser panel from quitting wmux - #431

Merged
amirlehmam merged 2 commits into
amirlehmam:masterfrom
alejandronava562:fix/browser-ctrl-w-quits
Nov 4, 2026
Merged

amirlehmam merged 2 commits into
amirlehmam:masterfrom
alejandronava562:fix/browser-ctrl-w-quits

Conversation

@alejandronava562

Copy link
Copy Markdown
Contributor

With the browser panel focused, Ctrl+W closes the entire wmux window instead of a tab. With one window open, that quits the app and every terminal in it.

Cause

wmux never calls Menu.setApplicationMenu, so Electron installs its default menu. The menu bar is hidden (titleBarStyle: 'hidden'), but its accelerators are still active:

Accelerator Default menu item
Ctrl+W Window → Close
Ctrl+R / Ctrl+Shift+R View → Reload / Force Reload
Ctrl+Shift+I Toggle Developer Tools
Ctrl+M Window → Minimize
Ctrl+0 / Ctrl+Plus / Ctrl+- Zoom

In the desktop renderer these never fire for a wmux binding, because useKeyboardShortcuts calls preventDefault on every key it claims, and a prevented key never reaches the menu. A <webview> guest has no such handler. A key its page leaves unhandled goes to the embedder and from there to the window's menu. So Ctrl+W in a page runs Window → Close. For the same reason, Ctrl+R in a page reloads the whole wmux UI, not the page, and Ctrl+M minimizes wmux.

Fix

ignoreMenuShortcutsInGuest (src/main/webview-menu-shortcuts.ts) calls contents.setIgnoreMenuShortcuts(true) on every webview guest, from the existing web-contents-created hardening hook. It only affects keys pressed while a page has focus:

  • the page still receives every key
  • the desktop renderer's menu behaviour is unchanged
  • popups the panel opens already run with setMenu(null)

Verification

I ran a dev build side by side with the installed wmux under WMUX_INSTANCE, opened a browser tab on example.com, focused the guest, and sent real input events from the main process (webContents.sendInputEvent):

Before After
Ctrl+W in the page window closes, app exits nothing happens to wmux
Ctrl+R in the page wmux UI reloads nothing happens to wmux
Ctrl+M in the page wmux minimizes nothing happens to wmux
Page keydown listener — sees Ctrl+w, Ctrl+r, Ctrl+m
Ctrl+W with the desktop renderer focused (control) closes the active tab closes the active tab
  • I dumped Menu.getApplicationMenu() from main to confirm the default menu, and that Close is bound to CommandOrControl+W.
  • Unit test: tests/unit/webview-menu-shortcuts.test.ts.
  • tsc -p tsconfig.node.json passes.

Not in scope

wmux's own shortcuts still don't fire while a page has focus: Ctrl+W there now does nothing, where a user might expect it to close the browser tab. Fixing that means forwarding guest keys to the desktop's shortcut dispatcher, which deserves its own PR. This one stops the data loss.

alejandronava562 and others added 2 commits November 4, 2026 11:05
wmux never sets an application menu, so Electron's default one is live
behind the hidden menu bar. A key the browser panel's page leaves
unhandled is passed to the embedder and on to that menu, so Ctrl+W ran
Window > Close on the whole window and the app quit. Ctrl+R reloaded the
entire wmux UI and Ctrl+M minimized it the same way.

Ignore menu shortcuts on every <webview> guest. The page still receives
every key, and the desktop renderer's menu behaviour is unchanged.
Slice the 'webview' blocks of hardenWebContents out of src/main/index.ts by
brace counting (comments blanked, strings skipped) and assert one of them
calls ignoreMenuShortcutsInGuest(contents), so the Ctrl+W guard cannot be
dropped or moved out of the guest branch without a failing test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@amirlehmam
amirlehmam force-pushed the fix/browser-ctrl-w-quits branch from 375bb12 to dc90256 Compare November 4, 2026 10:56
@amirlehmam

Copy link
Copy Markdown
Owner

Thank you, this is a real data-loss fix and the analysis is right: wmux never sets an application menu, so a key a page leaves unhandled reached Electron's default Window → Close.

I rebased it onto 2.55.2 and added one test on top. The existing test covered ignoreMenuShortcutsInGuest by itself, but removing its call from hardenWebContents left the suite green. The new test checks that the call sits in the webview branch there. Merging; it ships in the next release, together with #432.

@amirlehmam
amirlehmam merged commit 98bbf50 into amirlehmam:master Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants