Skip to content

feat(browser): open links beside their pane, focus link tabs, honor window.close() - #31844

Merged
AmoabaKelvin merged 9 commits into
mainfrom
browser-link-opening
Oct 23, 2026
Merged

AmoabaKelvin merged 9 commits into
mainfrom
browser-link-opening

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​342 $\color{#cf222e}{\Huge{\mathbf{−}}}$​43 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299
Prod 34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​583 $\color{#cf222e}{\Huge{\mathbf{−}}}$​67 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​516

ELI5

Clicking a link in the terminal or an agent chat used to throw a browser tab over the thing you were looking at, even when a browser was already open next to it. Now the link opens in the browser you can see. If none is visible, it opens in a new pane beside the one you clicked in. New tabs opened from links get keyboard focus, so Cmd/Ctrl+W closes them. Sign-in pages that say "you can close this window" now close their own tab.

What Changed

Where links from Orca open (terminal, agent chat, markdown/editor preview, PR checks)

  • A browser is visible in the workspace: the link becomes a new tab in that browser pane.
  • No browser is visible: the link opens in a split to the right of the pane you clicked in, so the terminal or agent stays on screen. An empty pane is filled instead of split.
  • The new tab gets keyboard focus, so Cmd/Ctrl+W closes it and focus goes back where it was.
  • New setting under Link Routing: Open links in the background. Off by default. When on, the link joins the browser without being selected, and focus stays in the terminal.
  • A link clicked in Agents View switches to the workspace view so you can see the tab. Before, it opened into a layout that wasn't on screen.
  • Local, SSH and paired-runtime workspaces, folder workspaces and the floating workspace all use the same rule. On a paired runtime the split is a client-only group that the existing runtime cleanup removes if the create fails.

Tabs opened from a page (target=_blank, window.open)

  • A foreground tab now takes keyboard focus, so Cmd/Ctrl+W closes it instead of the opener behind it. Cmd+click and middle-click still open in the background, as in Chrome.
  • The pane's focus request now waits for a new tab's guest to attach, and gives up if the user moves focus while it waits. Before, it gave up after 6 frames, which is why focus never reached a new tab.

window.close()

Why

Design

  • One rule, at the owner. openHttpLink is the single place every Orca-surface link goes through, so placement is decided there (http-link-browser-placement.ts) for both the local and the remote path. No caller changes.
  • The source pane is the active group. Clicking a pane focuses its group on pointerdown, so no source-tab id has to be threaded through the terminal, chat and markdown paths.
  • Split beside, not "reuse the sibling". "Open Preview to the Side" reuses an existing sibling pane, but here the sibling is often another agent. Covering it is the bug we're fixing.
  • Foreground by default, one opt-in background toggle. It matches Chrome (a link from another app opens in front) and VS Code's "open beside", which focuses the new editor. [Feature]: Option to open in-app browser links in a background tab #31530 asked for the background mode, and no modifier key is free for it: Cmd opens links and Shift picks the destination.
  • window.close() rule in the renderer. The renderer knows whether a page opened the tab, and the webview's canGoBack/canGoForward tell it the history length. The opened-by-page mark lives in memory only. The saved session schema drops unknown page fields, and Chrome also forgets openers after a restore.

Ruled out

  • Adding a sourceTabId to every link path. The active group already says where the click came from.
  • Placing the tab in a group that hides a browser behind another tab. That would cover whatever that group is showing.
  • Letting the guest's native close through. That is the crash path.
  • Setting placement per surface. One rule is easier to predict.

Built on what users asked for in #22686, #13392, #31536, #10549, #18834 and #27194. None of those PRs is merged here; this branch rebuilds the behaviour.

Linked Issue

Fixes #13390
Fixes #31530
Fixes #18832
Fixes #26939

#7813: a link clicked in Agents View now switches to the workspace view so the tab is visible. That's covered by a unit test only; I couldn't get an agent terminal into Agents View in the scratch profile.
#10546: links no longer cover a live agent. Browser tabs that agents open from the CLI or automation already open in the background; this PR doesn't change them.
#16020 (new tabs next to the active tab) is left out. It changes tab order for every tab kind and is waiting on a maintainer decision.

Visual Proof

Recorded in a hidden dev build (macOS, light theme) by driving real terminal clicks and in-page clicks. Cmd+W is sent through the main-process key path.

A. Link from the terminal, no browser open

Before: the tab covers the terminal After: opens beside it; Cmd+W closes it and focus returns to the terminal
before-A-terminal-link.mp4
after-A-terminal-link.mp4

B. Link from the terminal, browser already visible on the right

Before: opens over the terminal, browser on the right unused After: new tab in the visible browser
before-B-visible-browser.mp4
after-B-visible-browser.mp4

E. "Open links in the background" on (no browser / browser visible): focus stays in the terminal

after-E-background-no-browser.mp4
after-E-background-visible-browser.mp4

C. target=_blank link in a page, then Cmd+W

Before: Cmd+W closes the hidden opener After: Cmd+W closes the new tab and the opener comes back
before-C-target-blank.mp4
after-C-target-blank.mp4

Cmd+click still opens in the background (after): https://github.com/user-attachments/assets/41524bdf-c32b-4006-81a1-5c2505002cfa

D. A sign-in page that calls window.close() 1.5s after loading

Before: the tab stays After: the tab closes and its opener is shown
before-D-window-close.mp4
after-D-window-close.mp4

New setting (light / dark)

after-settings-light.png
after-settings-dark.png

Testing

  • Every flow above was run in a hidden dev build on macOS.

  • Focused tests: placement rule, background mode and Agents View in openHttpLink, page-opened tab focus, focus waiting for a new tab's guest (fails on main), the window.close() rule (single entry, navigated, opened-by-page, pinned, multi-page), and the preload channel pin.

  • Ran locally: check:code-quality:changed, check:react-doctor:changed, tc:web, tc:node. CI covers the rest.

  • Not tested live: SSH and paired-runtime workspaces (they go through the existing remote opener with the same placement fields), Windows and Linux (no platform-specific code here), and Agents View with a real agent.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Open questions for Kelvin

  • Foreground by default? With a split, the link takes focus. The alternative is to keep focus in the terminal by default and drop the setting.
  • Agents View. A link clicked there now leaves Agents View for the workspace view. The other option is to show it in the floating workspace panel, which fix(agents): keep Pi status through session_shutdown; open browser in Agents View #7838 tried.
  • Several visible browsers. The first one in layout order wins. Alternatives: the most recently used, or the one next to the source.
  • orca open-url ($BROWSER on headless runtimes, used by CLI OAuth) is placed by the runtime's own publish path, so it doesn't follow this rule yet. Worth a follow-up?

Narrower terminals and wrapped URLs. Opening links beside the terminal makes split panes more common. In CI the terminal came out exactly 36 columns wide, and http://localhost:18080/echo/modifier is 36 characters. A URL that exactly fills a row gets the next row (the prompt) joined on as its continuation by #31713's edge-wrap detection. The SSH e2e now prints a blank row after each URL. The detection itself is unchanged here; whether it should also check xterm's isWrapped is a question for #31713's owner.

Sibling branches

  • use-browser-page-chrome-focus.ts and browser-page-guest-focus.ts are shared with browser-page-focus-and-navigation. The edits are limited to the page-focus request: wait for real guest attachment, then yield to the user.
  • Focus landing on the page body after Cmd+W in a split belongs to that branch.

Mobile. Mobile only shows the host's screencast, so window.close() and page-opened tabs follow the desktop host. Mobile has no splits, so placement doesn't apply. A mobile "open links in background" would need its own setting.

Server-streamed pages (headless serve) have no close preload, so window.close() there still tears down the offscreen window. Not changed here.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Security: the page can only request a close. The renderer checks the rule, and nothing new is exposed to page script.
  • Compatibility: the new guest-to-embedder message travels within one app build. The remote opener request is in-renderer only, so no wire change. The new setting is optional and defaults off.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 22, 2026 21:59
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ee93b2f5-6a03-4388-9016-f74d082b98c3
📥 Commits

Reviewing files that changed from the base of the PR and between e01320f1ad9822b8fc46a8bb29d5f3ef55368db9 and 6d132ae.

📒 Files selected for processing: 2
  • src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.test.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The changes add guest window.close() handling, browser link placement and background-opening controls, and focus behavior that waits for browser guest attachment. The background-opening setting is added to shared settings, Browser settings search, and locale strings. HTTP link routing uses shared placement helpers for local and remote opens, and tab-opening requests can specify split targets.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 6d132

Foreground links may still leave keyboard focus behind or open beside the wrong pane. Resolve the remaining link-routing and focus paths before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning The changes meet the coding requirements for [#31530] and [#26939]. They add a default-off background setting for local and remote in-app links, and route eligible window.close() requests through th… For [#13390], add a default-off placement setting. Keep current new-tab placement when it is off. When it is on, resolve the clicked page's source group, reuse its layout sibling, and create a right split only when no sibling exists. For [#…
Docstring Coverage Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 41 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the primary changes: link placement, tab focus, and guest window-close handling.
Description check Passed The description is complete and covers the required sections, user impact, implementation details, linked issues, visual proof, testing, scope limitations, and compatibility considerations. The remain…
Out of Scope Changes check Passed The production changes and tests stay connected to the linked browser-link, tab-focus, and window.close() objectives. Runtime target handling, Agents View behavior, localization, focus-wait changes,…
Full details: Description check

Explanation

The description is complete and covers the required sections, user impact, implementation details, linked issues, visual proof, testing, scope limitations, and compatibility considerations. The remaining unchecked build commands are explicitly left for CI coverage, so they are non-critical.

Full details: Out of Scope Changes check

Explanation

The production changes and tests stay connected to the linked browser-link, tab-focus, and window.close() objectives. Runtime target handling, Agents View behavior, localization, focus-wait changes, and terminal URL test updates support those objectives. No demonstrated change is unrelated to the linked issue scope.

Full details: Linked Issues check

Explanation

The changes meet the coding requirements for [#31530] and [#26939]. They add a default-off background setting for local and remote in-app links, and route eligible window.close() requests through the normal tab-close path with tests. The changes do not meet [#13390]. Placement always uses a visible browser or a new right split. It does not provide the issue's opt-in placement mode, sibling reuse, or default new-tab behavior. The command-click case in [#18832] also remains a background action. Focus is requested only when activate is true, so the linked issue's command-click focus requirement is not met.

Resolution

For [#13390], add a default-off placement setting. Keep current new-tab placement when it is off. When it is on, resolve the clicked page's source group, reuse its layout sibling, and create a right split only when no sibling exists. For [#18832], ensure the command-click path activates and focuses the new tab before the user presses Cmd/Ctrl+W.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AmoabaKelvin
AmoabaKelvin force-pushed the browser-link-opening branch 2 times, most recently from b22107d to 45c8597 Compare October 22, 2026 22:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 814e5b30-77f8-4066-a1c6-fc21f88f7afb
📥 Commits

Reviewing files that changed from the base of the PR and between 31bffb8 and 45c85977630183a92b0134dd6a3a14b8f99bd833.

📒 Files selected for processing: 42
  • src/preload/browser-window-close-installation.ts
  • src/preload/browser-window-close.test.ts
  • src/preload/browser-window-close.ts
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-page-context-menu-items.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-page-guest-focus.ts
  • src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.test.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.ts
  • src/renderer/src/components/browser-pane/browser-client-page-retained-elements.ts
  • src/renderer/src/components/browser-pane/browser-client-page-retained-registry.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-webview.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts
  • src/renderer/src/components/settings/BrowserLinkRoutingBackgroundSetting.tsx
  • src/renderer/src/components/settings/BrowserPane.search-catalog.test.tsx
  • src/renderer/src/components/settings/BrowserPane.tsx
  • src/renderer/src/components/settings/browser-link-routing-copy.ts
  • src/renderer/src/components/settings/browser-search.test.ts
  • src/renderer/src/components/settings/browser-search.ts
  • src/renderer/src/hooks/ipc-events/browser-state-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/browser-state-open-link-profile.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/pt.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/browser-page-tab-opening.ts
  • src/renderer/src/lib/http-link-browser-placement.test.ts
  • src/renderer/src/lib/http-link-browser-placement.ts
  • src/renderer/src/lib/http-link-routing.test.ts
  • src/renderer/src/lib/http-link-routing.ts
  • src/renderer/src/lib/workspace-browser-tab-open.ts
  • src/renderer/src/main.tsx
  • src/renderer/src/runtime/web-runtime-browser-client-target-group.ts
  • src/renderer/src/store/slices/editor/tabs/editor-open-target-group.ts
  • src/shared/browser-guest-window-close.ts
  • src/shared/browser-link-opening-settings.ts
  • src/shared/default-global-settings.ts
  • src/shared/global-settings-base.ts
  • src/shared/telemetry-property-schemas.ts
  • tests/e2e/ssh-orcad-terminal-browser-link.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

🟡 Minor · Preserve the clicked pane while registering a localhost label. · http-link-routing.ts:213-214

src/renderer/src/lib/http-link-routing.ts:213-214
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve the clicked pane while registering a localhost label.

If the user clicks a link in pane A and selects pane B before registration completes, this callback reads the new active group. openLocalHttpLinkTab can then open the link beside pane B instead of pane A. Resolve the placement at click time and pass it through the registration callback.

🟡 Minor · Check user focus again when the guest attaches. · use-browser-page-chrome-focus.ts:231-233

src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.ts:231-233
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Check user focus again when the guest attaches.

If the user focuses the address bar after one wait frame and the guest attaches before the next frame, this branch skips the focus-change check. focusGuestNow() then takes focus from the address bar. Check whether focus moved before every guest-focus attempt, including the first frame with an attached guest.


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4edf73da-f623-4f12-8093-35cadace5d5a
📥 Commits

Reviewing files that changed from the base of the PR and between 45c85977630183a92b0134dd6a3a14b8f99bd833 and b9009b3.

📒 Files selected for processing: 12
  • src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.test.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.ts
  • src/renderer/src/components/editor/rich-markdown-editor-click-routing.test.ts
  • src/renderer/src/components/terminal-pane/terminal-link-action-routing.test.ts
  • src/renderer/src/components/terminal-pane/terminal-runtime-host-link-routing.test.ts
  • src/renderer/src/lib/http-link-browser-placement.ts
  • src/renderer/src/lib/http-link-modifier-routing.test.ts
  • src/renderer/src/lib/http-link-routing.test.ts
  • src/renderer/src/lib/http-link-routing.ts
  • src/renderer/src/lib/workspace-browser-tab-open.test.ts
  • src/renderer/src/lib/workspace-browser-tab-open.ts
  • src/renderer/src/store/index.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 418a9f74-6a2c-4530-81b4-42558068a1f2
📥 Commits

Reviewing files that changed from the base of the PR and between b9009b3 and e01320f1ad9822b8fc46a8bb29d5f3ef55368db9.

📒 Files selected for processing: 16
  • src/preload/browser-window-close.ts
  • src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.test.tsx
  • src/renderer/src/components/browser-pane/assemble-chrome/use-browser-page-chrome-focus.ts
  • src/renderer/src/components/settings/BrowserPane.tsx
  • src/renderer/src/components/settings/browser-search.test.ts
  • src/renderer/src/components/settings/browser-search.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/pt.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/http-link-browser-placement.ts
  • src/renderer/src/lib/http-link-routing.ts
  • src/renderer/src/lib/workspace-browser-tab-open.ts
🚧 Files skipped from review as they are similar to previous changes: 7
  • src/renderer/src/i18n/locales/pt.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Links from the terminal, chat and markdown used to cover the pane they came from.
Tabs opened from links now take keyboard focus, so Cmd/Ctrl+W closes them.

Fixes #13390
Fixes #31530
Fixes #18832
Follows the web rule: a tab a page opened, or one with a single history entry.
The native close stays blocked, since it destroyed the guest under a live webview (#11763).

Fixes #26939
The client page renderer also runs in a bare Electron fixture, so the window.close handler is
registered from main.tsx. The SSH link e2e prints a blank row after each URL now that links open
beside the terminal and narrow it.
…itch

An SSH page renders on this desktop, so the remote opener now returns its page id and the link
path focuses it like a local link. A pending page focus is dropped when the user leaves the tab.
… focus on attach

A labeled localhost link resolved its pane after an async lookup, so a click elsewhere moved it.
The page-focus wait now yields to user focus in the frame the guest attaches too.
…vent

A remote link's focus request can land after its pane mounted but before the guest attached; the
event path tried once and lost it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant