Repository navigation
Conversation
Opening a link in a new tab could leave keyboard focus on the opener, causing Cmd+W to close the parent tab instead of the newly opened tab. - request focus for tabs opened through links and the context menu - focus the embedder before handing focus to the attached webview - avoid restoring opener focus when dismissing the link-opening menu
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 15 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
-
Check name Status Explanation Title check ✅ Passed The title clearly and concisely describes the main change: focusing foreground browser tabs opened from image links. Description check ✅ Passed The description follows the required template and includes the user impact, implementation details, rationale, linked issue, visual proof, testing results, validation limits, review notes, and checkli… Linked Issues check ✅ Passed The changes satisfy the coding requirements for [ #18832]. Foreground link creation requests focus for the new active page. The focus handler now waits for an attached guest and focuses the browser win…Out of Scope Changes check ✅ Passed The changes stay within [ #18832]. The source changes implement foreground-tab focus transfer and focus-request lifecycle handling. The unit tests, image fixture, and image-link E2E test provide regres…
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Link-open IPC handler —
browser-state-ipc-bridge.tsnow queuesrequestBrowserFocusfor the newly created tab'sactivePageId, so keyboard shortcuts route to the destination guest instead of the opener. - Link context menu — "Open Link In Orca Browser" dismisses the menu without the opener-refocus in
closeMenu, then queues a focus request for the new page; other items keepcloseMenu(). - Shared webview focus adapter —
isAttached()now checksgetWebContentsId()before treating a guest as attachable, andfocus()callswindow.focus()beforewebview.focus(). - Queued-request consumption — a new
peekBrowserFocusRequestdefersconsumeto the first animation-frame attempt, preserving the request across StrictMode effect replay while keeping immediate consumption for address-bar requests. - Tests — unit coverage for the focus adapter, queued-request behavior, the IPC path, and the context-menu path; the E2E generic-link case is extended with a native
CmdOrCtrl+Wstep.
I verified the id semantics hold end-to-end (requestBrowserFocus({ pageId: newTab.activePageId }) keys the queue by page id, and useBrowserPageChromeFocus consumes with browserTabId = BrowserPage.id), and the StrictMode fix is correct: the deferred consume happens exactly once on the first frame attempt.
ℹ️ Native-focus verification only runs in foreground E2E
The step that actually proves the bug (that CmdOrCtrl+W closes the natively focused destination guest via webContents.getFocusedWebContents()) is skipped unless ORCA_E2E_FOREGROUND=1. The always-on assertion expect(destinationWebview).toBeFocused() checks DOM focus, not native webContents focus — it catches a regression in the webview.focus() half of the fix, but not in the window.focus() half that transfers OS keyboard focus, which is the part that was actually broken. In the default headless CI run that regression could return silently. This is a reasonable, disclosed limitation; noting it only so it's on the record that CI coverage here is DOM-level, not native.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
@pullfrog Added two @headful E2E cases covering target="_blank" links and context-menu link opening. They enable ORCA_E2E_FOREGROUND=1 through the fixture, verify the natively focused WebContents, and confirm that Cmd/Ctrl+W closes only the destination tab while preserving the opener. Both pass locally on macOS. The existing changed-E2E workflow selects this spec for headful execution when it is included in the PR diff. Existing tests, the default headless suite, and production code are unchanged. |
There was a problem hiding this comment.
ℹ️ No critical issues — two test-reliability notes inline.
Reviewed changes
- Native-focus E2E spec — added
tests/e2e/browser-link-native-focus.spec.ts, a@headful+ORCA_E2E_FOREGROUND=1spec that drives both link routes (target=_blankand context menu) and provesCmdOrCtrl+Wcloses the destination guest viawebContents.getFocusedWebContents(), closing the loop on the prior note that native-focus verification was skipped in the standard CI lane.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
The new native-focus spec is only verified on macOS, but the changed-e2e lane and the scheduled full suite run it on Ubuntu under bare xvfb-run — no window manager, no dbus session. BrowserWindow.getFocusedWindow() has never been exercised in that environment, so if X input focus is not established there, expectBrowserGuestFocused polls for windowFocused: true until its 10s expect timeout and fails, turning this PR's lane red and polluting every scheduled main-branch run. Confirm the spec actually passes on Linux CI (or gate it) before relying on it.
Reviewed changes
- Headful native-focus E2E spec — adds
tests/e2e/browser-link-native-focus.spec.ts, a@headfulspec that forcesORCA_E2E_FOREGROUND=1through the fixture and asserts the destination guest owns native keyboard focus (webContents.getFocusedWebContents()+BrowserWindow.getFocusedWindow()) after both atarget="_blank"click and the context-menu "Open Link In Orca Browser" path, then verifiesCmdOrCtrl+Wcloses only the destination tab while preserving the opener.
Technical details
# Verify native-focus spec on Linux CI before relying on it
## Affected sites
- tests/e2e/browser-link-native-focus.spec.ts:19-26 — `expectBrowserGuestFocused` polls `BrowserWindow.getFocusedWindow() !== null`
- tests/e2e/browser-link-native-focus.spec.ts:32 — `ORCA_E2E_FOREGROUND=1` forced with no platform/WM guard
## Required outcome
- Confirm the spec passes on the Ubuntu `changed-e2e` lane (bare `xvfb-run`, no WM) — the environment it actually runs in — not just macOS.
## Suggested approach (optional)
- If focus is not reliably established under Xvfb, either gate the spec to a platform where native focus is exercised (as the IME specs do via `ORCA_E2E_NATIVE_*`), or run the lane with a WM/dbus session (compare the computer-e2e lane's `dbus-run-session`).
## Open questions for the human (optional)
- Does bare Xvfb without a window manager assign X input focus such that `getFocusedWindow()` is non-null?DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ The retry refactor is clean and resolves the
getWebContentsIdconcern from the prior review; no new issues. I'm holding approval because the native-focus-on-Linux-CI concern raised earlier —expectBrowserGuestFocusedassertingBrowserWindow.getFocusedWindow() !== nullunder barexvfb-run— is still unaddressed.
Reviewed changes
- Guest-ID retry —
expectBrowserGuestFocusednow wraps the guest-ID read and the native-focus assertion inexpect(...).toPass({ timeout: 10_000 }), re-readinggetWebContentsId()on every attempt so a slow-attaching destination guest is awaited instead of throwing.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Verified on Linux under bare
|
|
Thanks for running this — that closes the open question cleanly, and the correction is right. Confirmed: One addition to my earlier note: both lanes actually run under a window manager, not bare Xvfb — No platform guard or timeout change needed — the native-focus concern on this spec is resolved.
|
Keep the background-tab behavior introduced by stablyai#18873 when resolving the link context-menu and browser gesture test conflicts.
Apply focus when the new tab is ready so CmdOrCtrl+W closes it and preserves the opener. Cancel pending focus when the user switches tabs or splits.
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Updated this PR after #18873 changed how background links are opened. Cmd/Ctrl-click and Open Link In Orca Browser now open the destination in the background and keep the current tab active. I removed this PR's earlier foreground-focus handling and test expectations for those routes to preserve that behavior. The remaining issue is reproducible on main with a plain click on a linked image: Click an image link that opens a new foreground tab. Without clicking inside the destination, press Cmd/Ctrl+W. The parent tab closes instead of the newly activated image tab. The follow-up uses the existing focus request mechanism for foreground opens. It waits until the guest can accept focus and cancels pending focus when the user switches tabs or splits, clicks elsewhere, or explicitly focuses the address bar. Background opens keep the behavior introduced in #18873. Native image-click/close-shortcut checks passed on macOS and Linux. The PR description now includes the image-click Before/After GIFs, updated test coverage, and the Linux/E2E validation limits. I merged main into this branch and added a follow-up commit, preserving the original three commits and keeping the discussion in this PR: Main merge: d6c3829 Final fix: 3d2c14d |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Foreground-only focus routing —
onOpenLinkInOrcaTabnow requests focus only whenactivateis true, and the "Open Link In Orca Browser" context-menu change from the earlier version was reverted, matching #18873's background-open policy for modifier-clicks and the context-menu route. - Pending-request cancellation — a queued guest-focus request is now consumed when the pane becomes inactive, a split loses shortcut scope, the renderer receives a
pointerdown, or the address bar is focused, so focus never lands in a tab the user has already left. - dom-ready retry —
webview-registry'sonRendererReadyre-requests a still-pending guest focus, completing it when the guest attaches after the six-frame retry budget instead of dropping it. - DOM-level E2E replacement — the native-focus spec (the source of the prior Linux CI concern) was removed and replaced with
browser-image-link-focus.spec.ts, which drives the image-click reproduction and asserts close-key routing at the DOM level, with native focus verified manually and documented.
I traced the id semantics (requestBrowserFocus({ pageId: newTab.activePageId }) keys by page id, consumed as browserTabId), the frame-loop / pointerdown / dom-ready interplay, and the StrictMode replay path, and confirmed the cancellation and retry paths cannot double-focus or drop a still-pending request.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…blank-focus # Conflicts: # src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.test.tsx
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Reject event-driven webview focus in an inactive split. · use-browser-page-chrome-focus.ts:266
src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.ts:266
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winReject event-driven webview focus in an inactive split.
isActivecan be true while another split owns focus, as the new test models. The changed mount effect discards a webview request whenchromeShortcutScopeisinactive, but this listener still callsfocusGuestNow()for a new request. If the guest is attached, that call steals focus from the other split. Apply the same scope check to event-delivered requests.
🟠 Major · Retain event-delivered webview requests until guest focus… · use-browser-page-chrome-focus.ts:255
src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.ts:255
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRetain event-delivered webview requests until guest focus succeeds.
When modal return-focus targets an active page whose guest is reattaching,
requestBrowserFocusdispatches synchronously. The listener consumes the request beforefocusGuestNow(), which can returnfalse. The laterdom-readyhandler then finds no pending request and does not retry focus.Peek at webview requests and consume them only after
focusGuestNow()returnstrue.Suggested fix
- const focusTarget = consumeBrowserFocusRequest(browserTabId) + const focusTarget = peekBrowserFocusRequest(browserTabId) if (!focusTarget) { return } if (focusTarget === 'address-bar') { + consumeBrowserFocusRequest(browserTabId) // Why: palette-triggered focus fights the same re-grab as a new tab does, so it takes // the bar the same bounded way rather than latching on a single try. startAddressBarFocusGrab() return } cancelAddressBarFocusGrab() - focusGuestNow() + if (focusGuestNow()) { + consumeBrowserFocusRequest(browserTabId) + }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 4b2f48be-d176-4c02-aa8b-98fb9f932ad3
📒 Files selected for processing (2)
src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.test.tsxsrc/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Merged
upstream/maininto the branch and adapteduse-browser-page-chrome-focus.tsto the upstream shortcut-scoping refactor: the Cmd/Ctrl+L guard now callsbrowserChromeShortcutOwnsEvent, and the forwardedonFocusBrowserAddressBarIPC is scoped to its own pane viabrowserPageId === browserTabId. - Reworked the focus hook's tests onto upstream's shared
paneChanneltest rig, carrying upstream's split and floating-panel chord-scoping cases alongside the PR's queued-focus cases.
No behavioral change reaches the fix itself: the queued guest-focus request, its address-bar and pointerdown cancellation, the six-frame retry, and the dom-ready re-request are untouched by the merge; every other file in the PR is byte-identical to the prior reviewed commit. pnpm tc:web and the 61 focused unit tests pass on the merged head.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Ignore guest focus requests in inactive splits. Keep requests pending until guest focus succeeds, and cancel them when the user moves focus elsewhere. Add regression tests for delayed attachment and cancellation.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Retained event-delivered guest focus — the
ORCA_BROWSER_FOCUS_REQUEST_EVENTlistener now peeks instead of consuming, and consumes a'webview'request only afterfocusGuestNow()succeeds, so a guest that attaches after the short frame budget still gets focus via thedom-readyre-request. - Rejected guest focus in inactive splits — the event listener consumes and drops a
'webview'request whenchromeShortcutScope === 'inactive', matching the mount effect, so a request can no longer steal focus from the split that owns shortcuts. - Moved
pointerdowncancellation — the capturepointerdownconsumer was lifted out of the mount effect's focus-loop branch into the active-pane event effect, so a retained event-delivered request is cancelled by a click even when no retry loop is running. - Unit coverage — added cases for retention across a late guest reattach, inactive-split rejection, cancellation on
pointer/address-bar/split/tabinput, and no replay after the pane goes inactive.
I re-read both effects end-to-end and traced the retain → dom-ready retry → consume-on-success path, the cancellation paths (pointerdown, address-bar focus, isActive/scope change), and the StrictMode replay contract. The focusAddressBarNow consume was already present on 56e2b68 (added in 3d2c14d), so this delta only re-scopes and retains. Verified locally: 72 focused unit tests pass across the four changed test files and pnpm tc:web is clean. All prior Pullfrog threads remain resolved.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
@coderabbitai review Both findings were addressed in f2146f4:
Regression tests were added. Please verify both findings against the latest commit |
✅ Action performedReview finished.
|
Preserve source tab placement and execution host inheritance while retaining foreground guest focus requests.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Merged
upstream/main(21f8e0f) into the branch — the range-diff vs the prior reviewed head touches onlybrowser-state-ipc-bridge.ts; upstream'sresolveBrowserSourceUnifiedTabrefactor now lives there. - Merge adaptation preserves the fix — the PR overlay is unchanged:
const newTab = createBrowserTab(...)plusrequestBrowserFocus({ pageId: newTab.activePageId, target: 'webview' })for foreground opens. - No focus-handling gap from the new host route — the focus request is consumed through
useBrowserPageChromeFocus, which every pane variant mounts.
Verified browser-state-open-link-profile.test.ts and browser-workspace-source-resolution.test.ts pass (10 tests) on the merged head. All prior Pullfrog threads remain resolved.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Keep the foreground browser focus request alongside main's updated runtime ownership lookup. Validated with 116 focused tests, tc:web, and lint/format checks on the conflict resolution.
Reuse main's shared tab-opening and guest-attachment flow while retaining pending focus until readiness or cancellation. Validated 119 passing tests plus one existing expected failure and targeted lint/format checks. Web typecheck remains blocked by main's Jira type imports.
|
Thanks @hwantage for digging into why focus never reached the new tab! This is already fixed on main by #31844 (291e2e8): a foreground tab opened from a page (target=_blank, window.open) now queues a webview focus request, and the pane's focus retry waits up to 120 frames for the new guest to attach before starting its budget, giving up if the user moves focus meanwhile, so Cmd/Ctrl+W closes the new tab rather than its opener. Background opens (activate: false, Cmd+click, middle-click) still leave focus where it was. If you can still reproduce the opener closing after clicking a linked image on the latest build, please comment or reopen. |
|
@nwparker, could you reopen this PR? GitHub does not allow me to reopen it. The plain image-click case still reproduces on main after #31844 (macOS):
Actual: The original tab closes; the image tab remains. The same manual steps fail on main and pass with the prepared fix: This screenshot explains the steps using the original PR recordings: |


ELI5
Clicking a linked image opens a new tab, but Command+W can still close the original tab. This fixes the remaining image-click case after #31844.
Prepared update: dc4e0150b0, limited to 4 files. The current PR diff will be replaced after a maintainer reopens it.
Reproduction (macOS)
Actual on main: The original tab closes; the image tab stays open.
Expected / prepared update: Only the image tab closes; the original tab stays open.
What Changed
Call
window.focus()beforewebview.focus()in the existing guest-focus adapter. Main's focus-request and attachment-wait handling stays in place.Fixes #18832.
Visual Proof
Annotated screenshots from the original PR recordings; the tab strips are enlarged to show which tab closes.
Original before/after recordings
Before: main
adcc30be3b. After: earlier PR implementation. These are the original recordings, not new captures of today's main.Testing
AI Disclosure
Assisted by Claude Code and OpenAI Codex; this narrowed update was prepared and self-reviewed with Codex.
Agent skill upstream boundary