Skip to content

[Bug]: [Browser] Keyboard focus is lost when switching between a terminal tab and a browser tab #20533

Closed

Description

@kimdane0115

Operating system

macOS

Orca version

1.4.202(1.4.202)

Details

Summary

Switching from any other tab to a browser tab activates the browser tab visually, but native keyboard focus does not move into the page. Typing, keyboard scrolling, and Cmd+F do not reach the page until it is clicked.

The loss is one-directional. Switching from a browser tab back to a terminal tab works correctly: the terminal takes keyboard focus immediately and accepts input without an extra click. Only the browser pane fails to take focus on activation.

This looks like the same underlying cause described in #18832 and in PR #18834: tab activation alone does not transfer native keyboard focus to the guest.

Repro

  1. Open a worktree with a terminal tab and a browser tab in the same tab strip.
  2. Focus the terminal tab and type a character to confirm it has keyboard focus.
  3. Switch to the browser tab (tab strip click / Ctrl+Tab / Cmd+number).
  4. Without clicking inside the page, press arrow keys, Space, or Cmd+F.

Actual: The browser tab renders as active, but keystrokes are dropped or still delivered to the previously focused surface. A click inside the page is required before any input reaches it.

Expected: Activating a browser tab moves native keyboard focus into its page, so scrolling and typing work immediately without an extra click.

Counter-case (works as expected)

  1. From the browser tab above, click inside the page so it holds focus.
  2. Switch back to the terminal tab.
  3. Without clicking the terminal, type a character. Input reaches the terminal normally.

Frequency

Reproducible on every switch into a browser tab

Notes

  • Entry points tried: tab strip click / Ctrl+Tab / Cmd+number
  • Also occurs when the browser tab is in a split: yes / no
  • Also occurs when switching from an editor tab (not only a terminal tab): yes / no

Workaround

Click once inside the page after switching to the browser tab. Focusing the address bar and tabbing out of it also restores input in the browser pane.

Related

Activity

  1. added theissue type on Sep 14, 2026
  2. L4XB commented on Sep 14, 2026

    @L4XB
    Contributor

    Traced this on main (8e26d516). The asymmetry you describe is structural, not a timing race, and it is narrower than "the same cause as #18832".

    The two panes take focus in different ways

    The terminal focuses itself from its own activation. TerminalPaneRuntimePortals.tsx passes the flag straight down:

    shouldFocus={isActive && isVisible && activePane?.id === pane.id}

    So "this pane became active" is the focus trigger. Nothing has to ask.

    The browser guest only focuses when someone queued a request for it. useBrowserPageChromeFocus has an isActive-gated effect, and its first act is to look for a queued request:

    const focusTarget = consumeBrowserFocusRequest(browserTabId)
    if (!focusTarget) {
      return
    }

    Nothing queued → it returns, and becoming active focuses nothing.

    Which is why the omnibox works and the tab strip does not

    Inside src/renderer/src/components/tab-bar/, exactly one non-test file calls requestBrowserFocus: open-tab-selection-routing.ts, the omnibox "switch to tab" path —

    return {
      status: 'activated',
      focus: () => requestBrowserFocus({ pageId: activation.pageId, target: activation.focusTarget })
    }

    The tab-strip runtime model does not, and neither does anything else on the plain-activation path. So a tab-strip click, Ctrl+Tab and Cmd+<n> all leave the guest unfocused, while the same destination reached through the omnibox takes focus correctly.

    Worth checking against your repro: switching to the browser tab through the omnibox instead of the tab strip should work today. If it does, that confirms the split above and narrows the fix to the activation path rather than the guest-attach timing #18834 is about.

    Two ways to close it, and the thing either must not break

    1. Queue at the activation sites — mirror what open-tab-selection-routing.ts already does, wherever the tab strip sets the active tab. Explicit, but it is one call per entry point and a new entry point will forget it. That is how this one was born.
    2. Focus on becoming active in the hook — give useBrowserPageChromeFocus the same "activation is the trigger" rule the terminal has, with the queued request staying an override rather than a precondition. One place, and new activation paths get it for free.

    (2) has a guard it must not lose: a new blank tab has to keep landing in the address bar with its text selected, which today works because that path queues an address-bar request. Under (2) the fallback has to fire only when nothing is queued and the address bar is not already held — keepAddressBarFocusRef and the in-flight grab are both right there to read. Getting that wrong would yank focus out of the bar mid-typing whenever isActive re-fires.

    Overlap worth knowing before anyone starts

    PR #18834 is open and edits this same hook (it adds peekBrowserFocusRequest to use-browser-page-chrome-focus.ts). Its subject is different — focusing a newly opened foreground tab once its guest attaches — but a fix for this issue written against main will conflict with it. Whoever takes this should probably stack on #18834 rather than race it.

    I have not opened a PR for exactly that reason; happy to do so if a maintainer says which of (1)/(2) you want and whether to base it on #18834.


    Investigated with Claude Code; the file/line claims above are from reading and grepping the tree at 8e26d516, not from running the desktop app — I have no way to reproduce the focus behaviour itself here, which is why the omnibox counter-check above is worth a maintainer's ten seconds.

  3. kimdane0115 commented on Sep 15, 2026

    @kimdane0115
    Author

    Confirmed — the split is real.

    Works (focus lands in the page): Cmd+J palette → browser tab. Arrow keys and Space scroll immediately, no click needed.

    Fails (no focus): tab strip click, and Ctrl+Tab (bound to Previous recent tab in my keymap). Page stays unfocused until clicked.

    Same destination tab in all three cases, same session, terminal tab focused before each attempt.

    So your read looks right: the palette path is the only one queuing a focus request, and plain activation leaves the guest unfocused.

    On the two options — (2) reads better from a reporter's seat, since (1) is exactly the shape that produced this gap: Ctrl+Tab and the tab strip are separate entry points and both were missed. Not my call on the guard trade-off, though.

    Keymap note in case it matters for enumerating entry points: Tab Navigation has Next/Previous tab (same type), Next/Previous tab (all types), Previous recent tab, Next/Previous terminal tab, and Select Tab 1–9 — several distinct activation paths, all presumably on the unfocused side.

  4. AmethystLiang commented on Sep 16, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

  5. added 4 commits that reference this issue on Oct 23, 2026
    fbd11ea
    c59cc8f
    5a6ace6
    018b291
  6. added 2 commits that reference this issue on Oct 25, 2026
    5afe0ad
    03e18c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

browserbugSomething isn't workingos:macosIssues affecting macOS

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions