← reports

#7830 · Native browser close-command interception

BugPriority: MediumEffort: Lowdesktopconfirmed-repro Issue · November 19, 2026 · base df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2

Verdict: REPRODUCED at the production shortcut-routing boundary. Root-cause confidence: high for the missing interception. The final macOS native window-close outcome was not exercised on this Linux host.

1. TL;DR

The desktop app embeds web pages in a separate native browser view. When that view owns keyboard focus, app shortcuts must be forwarded to the host renderer rather than reaching native menu handling. The production resolver rejects the default close-panel binding because it has no browser-focus condition and is absent from the resolver's explicit exception list. A focused test reproduced this missing dispatch twice on unchanged trusted main, in separate clean checkouts. The narrow repair admits the existing close-panel command; it does not alter menu policy, keybinding conditions, or any public interface.

Evidence boundary: these runs prove that Command+W returns null instead of panel.close at the real resolver. They do not prove that every macOS menu path always closes the whole window. No screenshot or live macOS result is claimed.

2. Claims vs findings

ClaimStatusEvidence
The close-panel binding is not routed from native page focus.VerifiedBoth clean runs fail the close-command assertion with received null; browser-scoped positive control passes.
The default binding is Mod+W without browserFocus.VerifiedServer defaults use mainSurface and exclude modalOpen.
The native input handler leaves an unresolved shortcut unconsumed.Verified in sourceIt returns before preventDefault and dispatch when resolution is null.
The macOS window closes rather than the selected browser tab.Unverified liveNo macOS desktop or native input automation is available. The native menu and renderer-close fallback provide a plausible route, not an observed final outcome.
Changing only the shortcut cannot bypass the resolver exclusion.VerifiedA rebound close-command regression also returns null before the fix; command eligibility is checked before key matching.
Reported historical releases behave identically.UnverifiedOnly trusted current main was executed, not historical release binaries.

3. Environment

4. Minimal reproduction

  1. Clone the trusted public repository, fetch main, and detach at the recorded base:
    git clone https://github.com/get-bb/bb.git bb-7830-repro
    cd bb-7830-repro
    git fetch origin main
    git checkout --detach df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2
    pnpm install --frozen-lockfile --prefer-offline
  2. Save the complete test below as apps/desktop/test/issue-7830-repro.test.ts. This fixture follows the verified server binding and invokes the production resolver without mocking it.
  3. Run:
    pnpm exec turbo run test --filter=@bb/desktop -- --run test/issue-7830-repro.test.ts
  4. Expected: the close-panel case passes and returns panel.close. Actual, in both unchanged checkouts:
    AssertionError: expected null to be 'panel.close' // Object.is equality
    
    - Expected:
    "panel.close"
    
    + Received:
    null
    
    Test Files  1 failed (1)
         Tests  1 failed | 2 passed (3)

Complete reproduction test

import { describe, expect, it } from "vitest";
import type { AppKeybindings } from "@bb/domain";
import { resolveDesktopBrowserAppCommand } from "../src/desktop-browser-shortcuts.js";

describe("native browser close shortcut routing", () => {
  const closeBinding: AppKeybindings[number] = {
    command: "panel.close",
    desktopOnly: false,
    shortcut: {
      key: "w",
      mod: true,
      meta: false,
      control: false,
      alt: false,
      shift: false,
    },
    when: { all: ["mainSurface"], none: ["modalOpen"] },
  };
  const input = {
    key: "w",
    code: "KeyW",
    metaKey: true,
    ctrlKey: false,
    altKey: false,
    shiftKey: false,
  };

  it("dispatches the close-panel command for macOS Command+W", () => {
    expect(
      resolveDesktopBrowserAppCommand({
        input,
        platform: "darwin",
        keybindings: [closeBinding],
      }),
    ).toBe("panel.close");
  });

  it("does not dispatch a command for an unrelated shortcut", () => {
    expect(
      resolveDesktopBrowserAppCommand({
        input: { ...input, key: "q", code: "KeyQ" },
        platform: "darwin",
        keybindings: [closeBinding],
      }),
    ).toBeNull();
  });

  it("routes an existing browser-scoped command", () => {
    expect(
      resolveDesktopBrowserAppCommand({
        input: { ...input, key: "l", code: "KeyL" },
        platform: "darwin",
        keybindings: [
          {
            ...closeBinding,
            command: "browser.focusLocation",
            shortcut: { ...closeBinding.shortcut, key: "l" },
            when: { all: ["mainSurface", "browserFocus"], none: [] },
          },
        ],
      }),
    ).toBe("browser.focusLocation");
  });
});

This is a keyboard-routing defect, not a rendering defect. No simulated image is used. Reproduction source and output are inline because this reports repository forbids committed test files and raw log artifacts.

5. Root cause

Server binding context and default panel bindings define close-panel as a main-surface shortcut, not a browser-only action:

const mainWithoutModal = {
  all: ["mainSurface"],
  none: ["modalOpen"],
};
binding("panel.close", "w", { mod: true }, mainWithoutModal)

The native-browser resolver eligibility filter skips bindings lacking browserFocus unless they belong to its explicit navigation exceptions. Close-panel is not an exception. Consequently it never reaches shortcut matching, including when rebound.

The native before-input-event handler then takes this branch:

if (command === null) return;
event.preventDefault();
...
args.dispatchAppCommand({ command, hostWebContentsId: hostWindow.webContents.id });

Returning null therefore leaves the keystroke unconsumed and prevents app-command dispatch. The native close menu item and its main-process close handler are the fallback path. Renderer close requests have a window-close timeout; an unhandled renderer response also closes the window. These are verified source paths, not proof of which native branch the reporter reached.

The renderer's existing close-panel and close-window handling already owns tab selection and closure. The fix must reuse that path rather than add a second native tab-closing implementation.

6. Proposed fix and regression proof

Admit panel.close beside the existing panel-navigation exceptions in the native-browser resolver. Leave the shortcut, context, renderer command handling, and native close-window fallback unchanged. Do not broaden this fix to other panel commands without their own evidence.

The candidate patch changes 26 text lines across two files: one production addition and 25 test additions. It extends the existing rebound-command table and adds the default Command+W regression in the established resolver test file. No dependencies, generated files, protocols, persistence, packaging, permissions, or public API are changed.

Before repair, existing resolver test file with new cases:
Test Files  1 failed (1)
     Tests  2 failed | 10 passed (12)

After one-line repair:
Test Files  1 passed (1)
     Tests  12 passed (12)

Relevant browser-view, shortcut, menu-shortcut, and menu suites:
Test Files  4 passed (4)
     Tests  155 passed (155)

Desktop typecheck, formatting check, and git diff --check pass. The full desktop package run has 646 passing tests, two skipped tests, and one failing packaging test. That same packaging test fails on the unchanged second checkout because the Electron executable cannot load libglib-2.0.so.0; it is unrelated to command routing.

7. Verification

The same agent repeated the reproduction directly in a second clean detached checkout at the exact recorded base. Before adding the test its tracked working tree was clean. It used a separate frozen install and the same Turbo command, without copying production outputs or modifying production files. The result again was one failed close-command case and two passing controls. No ports or data directories were needed. This is a repeated clean verification, not an independent review.

No report correction was necessary for the resolver result. The report deliberately limits its live claim: macOS native window closure and post-fix native tab removal were not observed. The desktop close-routing and embedded-browser native UI recipes remain blocked on platform prerequisites rather than marked passed.

8. Related issues and pull requests

No linked open pull request was present in the issue timeline or open-PR search before the candidate fix. No linked pull request branch was checked out or executed. No separate related issue was independently investigated.

9. Appendix and commands

pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build
pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk
pnpm exec turbo run build
pnpm exec turbo run test --filter=@bb/desktop -- --run test/issue-7830-repro.test.ts
pnpm exec turbo run test --filter=@bb/desktop -- --run test/desktop-browser-shortcuts.test.ts
pnpm exec turbo run test typecheck --filter=@bb/desktop
pnpm exec turbo run test --filter=@bb/desktop -- --run test/desktop-browser-shortcuts.test.ts test/desktop-browser-view-manager.test.ts test/desktop-menu-shortcuts.test.ts test/menu.test.ts
pnpm exec turbo run typecheck --filter=@bb/desktop
pnpm exec turbo run test --filter=@bb/desktop -- --run test/electron-builder-config.test.ts
pnpm exec oxfmt --check apps/desktop/src/desktop-browser-shortcuts.ts apps/desktop/test/desktop-browser-shortcuts.test.ts
git diff --check
git diff --numstat origin/main

The normal broad build was attempted but blocked before the reproduction by pre-existing plugin-SDK output ordering: plugin GitHub needs SDK process/host dist files before the parallel SDK build finishes. Running build:types resolved type exports but not those missing runtime outputs. The reproduction and relevant desktop tests do not require the broad app bundle and ran successfully to their stated outcomes. No unrelated build fix was made.

The verification inventory preflight also reports an unrelated unmapped diagnostics CLI family; no inventory baseline was rewritten. An initially combined filtered test/typecheck invocation passed a test-only flag to the compiler and was corrected by running those tasks separately; the successful commands above are the final evidence.

All issue content was treated as untrusted claims. No issue-supplied command, code, patch, branch, or external attachment was executed. This report contains only repository-derived descriptions and an agent-authored test.