Scope DevTools shortcuts to Harnss window to stop global Cmd+Alt+I interception#38
Scope DevTools shortcuts to Harnss window to stop global Cmd+Alt+I interception#38
Conversation
Co-authored-by: OpenSource03 <29690431+OpenSource03@users.noreply.github.com> Agent-Logs-Url: https://github.com/OpenSource03/harnss/sessions/0e68305c-7295-4057-b260-63ecce60384d
There was a problem hiding this comment.
Pull request overview
This PR fixes a macOS bug where Harnss was intercepting browser DevTools shortcuts globally by moving DevTools shortcut handling from Electron’s globalShortcut API to per-window input handling on mainWindow.webContents.
Changes:
- Remove global accelerator registration/unregistration for DevTools shortcuts.
- Add
before-input-eventhandler on the main window to open DevTools only when Harnss is focused. - Introduce
isDevToolsShortcuthelper with platform-aware modifier matching, plus unit tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| electron/src/main.ts | Removes global shortcut registration and adds window-scoped before-input-event DevTools handling. |
| electron/src/lib/devtools-shortcuts.ts | Adds a dedicated helper to detect supported DevTools shortcut combinations. |
| electron/src/lib/tests/devtools-shortcuts.test.ts | Adds unit tests to validate shortcut detection across platforms. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| mainWindow.webContents.on("before-input-event", (event, input) => { | ||
| if (!isDevToolsShortcut(input, process.platform)) return; | ||
| event.preventDefault(); | ||
| log("DEVTOOLS", `Shortcut ${input.key} triggered`); | ||
| openDevToolsWindow(); | ||
| }); |
There was a problem hiding this comment.
before-input-event will fire repeatedly on key repeat. With the current implementation, holding the shortcut can call openDevToolsWindow() multiple times before the first call finishes (especially in the glassEnabled path where it does an async HTTP fetch), which can result in multiple concurrent requests and potentially multiple DevTools windows. Consider ignoring input.isAutoRepeat and/or adding a re-entrancy/pending-open guard around openDevToolsWindow().
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f0a297adb6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| mainWindow.webContents.on("before-input-event", (event, input) => { | ||
| if (!isDevToolsShortcut(input, process.platform)) return; |
There was a problem hiding this comment.
Handle DevTools shortcuts for attached webview contents
This listener is attached only to mainWindow.webContents, so shortcuts are processed only when the main renderer has focus. In this app, the Browser panel uses an Electron <webview> (a separate guest WebContents), and key events in that guest do not route through the host page’s before-input-event handler; as a result, F12 / CmdOrCtrl+Alt+I / CmdOrCtrl+Shift+J stop working while focus is inside the webview, which regresses the prior in-app shortcut behavior. Consider also wiring the same shortcut handler to guest webcontents (e.g., via did-attach-webview / web-contents-created).
Useful? React with 👍 / 👎.
Summary
While Harnss is open,
Cmd+Alt+Iwas being captured globally, so browser DevTools shortcuts opened Harnss DevTools instead.Replaced global accelerator registration with window-scoped key handling on
mainWindow.webContentsso shortcuts only work when Harnss is focused.Extracted shortcut matching into a dedicated helper (
electron/src/lib/devtools-shortcuts.ts) with platform-aware logic (macOSCmd, othersCtrl).Added focused unit tests for shortcut detection (
electron/src/lib/__tests__/devtools-shortcuts.test.ts).Shortcut handling changes
globalShortcut.register(...)) removed.before-input-eventwhen the focused Harnss window receives matching input.Behavioral intent
F12,Cmd/Ctrl+Alt+I,Cmd/Ctrl+Shift+J).Type of Change
Related Issues
How to Test
Cmd+Alt+I; verify browser DevTools opens and Harnss is not brought to front.Cmd+Alt+I/Cmd+Shift+J/F12; verify Harnss DevTools opens as expected.Screenshots / Screen Recording
N/A — shortcut-routing fix (no visible UI delta).
Checklist
pnpm build)anytypes introducedms-*/me-*instead ofml-*/mr-*)wrap-break-wordshared/types/, notsrc/types/Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
www.electronjs.org/opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/harnss/harnss/node_modules/.pnpm/@electron+rebuild@4.0.3/node_modules/@electron/rebuild/lib/module-type/node-gyp/worker.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.