Skip to content

Scope DevTools shortcuts to Harnss window to stop global Cmd+Alt+I interception#38

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-cmd-alt-i-handling
Open

Scope DevTools shortcuts to Harnss window to stop global Cmd+Alt+I interception#38
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-cmd-alt-i-handling

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

Summary

  • While Harnss is open, Cmd+Alt+I was being captured globally, so browser DevTools shortcuts opened Harnss DevTools instead.

  • Replaced global accelerator registration with window-scoped key handling on mainWindow.webContents so shortcuts only work when Harnss is focused.

  • Extracted shortcut matching into a dedicated helper (electron/src/lib/devtools-shortcuts.ts) with platform-aware logic (macOS Cmd, others Ctrl).

  • Added focused unit tests for shortcut detection (electron/src/lib/__tests__/devtools-shortcuts.test.ts).

  • Shortcut handling changes

    • Global registration (globalShortcut.register(...)) removed.
    • DevTools open path now runs from before-input-event when the focused Harnss window receives matching input.
  • Behavioral intent

    • Preserve existing in-app DevTools shortcuts (F12, Cmd/Ctrl+Alt+I, Cmd/Ctrl+Shift+J).
    • Eliminate cross-app shortcut capture.
mainWindow.webContents.on("before-input-event", (event, input) => {
  if (!isDevToolsShortcut(input, process.platform)) return;
  event.preventDefault();
  openDevToolsWindow();
});

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 🎨 UI / design improvement
  • ⚡ Performance improvement
  • ♻️ Refactor (no functional changes)
  • 🧪 Tests / CI
  • 📝 Documentation

Related Issues

How to Test

  1. Open Harnss and keep it running in the background.
  2. Focus Chrome/Firefox and press Cmd+Alt+I; verify browser DevTools opens and Harnss is not brought to front.
  3. Focus Harnss and press 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

  • I've tested this on macOS (required for Electron/native features)
  • TypeScript compiles with no errors (pnpm build)
  • No any types introduced
  • Logical margins used (ms-*/me-* instead of ml-*/mr-*)
  • User-generated content containers have wrap-break-word
  • New shared types go in shared/types/, not src/types/
  • Large components/hooks are decomposed into sub-components/sub-hooks if needed

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
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>[Bug]: Harnss seems to capture cmd+alt+I from other browsers</issue_title>
<issue_description>### Description

While Harnss is open, trying to open inspector/devtools in other browsers using CMD+ALT+I brings up the developer tools within Harnss

Steps to Reproduce

  1. Have Harnss open
  2. Switch to a browser (I have experienced this in Firefox, Chrome & Chrome Canary)
  3. Use the shortcut CMD+ALT+I

Expected Behavior

Developer tools in the current browser should open

Actual Behavior

Developer tools from Harnss opens and is brought to the front

AI Engine

Not engine-specific

Operating System

macOS (Apple Silicon)

Harnss Version

0.21.4

Area

UI / Layout

Logs / Error Output

N/A

Additional Context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@OpenSource03 Ah yes, I am aware of it. Will fix it in one of the next versions

💬 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.

Co-authored-by: OpenSource03 <29690431+OpenSource03@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenSource03/harnss/sessions/0e68305c-7295-4057-b260-63ecce60384d
Copilot AI changed the title [WIP] Fix CMD+ALT+I shortcut behavior in Harnss Scope DevTools shortcuts to Harnss window to stop global Cmd+Alt+I interception Mar 20, 2026
Copilot AI requested a review from OpenSource03 March 20, 2026 23:01
@OpenSource03 OpenSource03 marked this pull request as ready for review March 21, 2026 02:46
@OpenSource03 OpenSource03 requested a review from Copilot March 21, 2026 02:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-event handler on the main window to open DevTools only when Harnss is focused.
  • Introduce isDevToolsShortcut helper 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.

Comment on lines +154 to +159
mainWindow.webContents.on("before-input-event", (event, input) => {
if (!isDevToolsShortcut(input, process.platform)) return;
event.preventDefault();
log("DEVTOOLS", `Shortcut ${input.key} triggered`);
openDevToolsWindow();
});
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +154 to +155
mainWindow.webContents.on("before-input-event", (event, input) => {
if (!isDevToolsShortcut(input, process.platform)) return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

[Bug]: Harnss seems to capture cmd+alt+I from other browsers

3 participants