Skip to content

feat(browser): open routed links in the browser already on screen - #22686

Closed
lucacri wants to merge 3 commits into
stablyai:mainfrom
lucacri:lucacri/open-browser-in-side-panel
Closed

lucacri wants to merge 3 commits into
stablyai:mainfrom
lucacri:lucacri/open-browser-in-side-panel

Conversation

@lucacri

@lucacri lucacri commented Sep 24, 2026

Copy link
Copy Markdown

ELI5

If you already have a browser open in one pane and click a link somewhere else (a terminal, a markdown file, the checks panel), Orca opens that link in a new tab on top of the pane you clicked in. The browser that is already on screen is ignored, so the link covers your terminal. With this change the link opens as a new tab in the browser that is already showing.

What Changed

  • Before: in a split layout (for example a terminal on the left and a browser on the right), cmd/ctrl-clicking a link in the terminal opens a new browser tab in the terminal's pane, covering the terminal.
  • After: the link opens as a new tab in the right-hand browser pane, which becomes its active tab, and focus moves there. The page that was showing stays open as its own tab. With no browser on screen, links open exactly where they did before.

Rules:

  • A browser counts only if it is the active tab of a pane in the worktree's layout. A browser tab hidden behind another tab does not count.
  • If several panes show a browser, the focused one wins. Otherwise the one focused most recently (Tab.lastFocusedAt) wins.
  • Only the same worktree's panes are considered; each worktree keeps its own browser.

Mechanism: one pure selector, findVisibleBrowserLinkTarget in src/renderer/src/lib/visible-browser-link-target.ts, walks the layout's groups and returns { targetGroupId } for the one to use. It reuses getEffectiveLayoutForWorktree, collectLayoutGroupIds and getGroupActiveTab. Two call sites pass that target into the targetGroupId option createBrowserTab already accepts:

  • openHttpLink (http-link-routing.ts): terminal links (local, runtime, SSH), markdown preview and editor links, and checks-panel links. The remote path forwards targetGroupId to the existing workspace browser opener. It already accepts that field, so there is no wire change.
  • onOpenLinkInOrcaTab (browser-state-ipc-bridge.ts): target=_blank popups from inside a browser page, which do not go through openHttpLink.

The labeled-localhost path opens after an await, so it now reads the layout fresh at that moment instead of reusing the state from the click.

Why

The alternatives were:

  • Loading the link into the visible page. That throws away the page you were reading.
  • Adding it as a hidden second page inside the existing browser tab. A browser tab can hold several pages internally, but there is no UI to switch between them, so the old page would be lost from view.

A new tab in the pane that already shows a browser keeps both pages one click apart, and reuses the tab-creation path every other browser tab uses.

Editors already have a similar rule (resolveEditorOpenTargetGroupId), which redirects a file only when it is opened from a terminal. Links redirect from any focused pane instead. A link clicked in a markdown preview should not cover the preview when a browser is right beside it.

Explicit "new browser tab" actions are unchanged: the new-tab button, orca browser tab create, port opening and file previews. They ask for a tab, not for a link to be routed.

Linked Issue

No linked issue.

Visual Proof

None yet. I have not recorded a before/after; the behavior is covered by unit tests only (see Testing).

Testing

  • I manually tested these changes locally

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

  • visible-browser-link-target.test.ts:

    • the focused browser pane wins, otherwise the most recently focused, and ties go by layout order;
    • a browser hidden behind another tab is ignored, and so is a group outside the layout;
    • a focused editor pane still redirects;
    • no recorded layout falls back to the renderer's default, another worktree is never used, and empty state is safe.
  • http-link-routing.test.ts:

    • a local link opens in the visible browser group and focuses it;
    • SSH and runtime links ask the remote opener for that group;
    • a hidden browser keeps today's placement;
    • system-browser links (setting or modifier) leave groups alone;
    • the delayed labeled-localhost path computes placement when the label resolves.
  • browser-state-open-link-profile.test.ts: a popup opens in the visible browser group with its opener's profile. A background popup is placed there without moving focus.

  • browser-link-placement.test.ts: against the real store, a link joins the pane that shows a browser.

pnpm typecheck (web), the changed-code quality gate, and the renderer lib, hooks/ipc-events, terminal-pane and store/slices test suites pass. Tested on macOS only; nothing here is platform-specific.

AI Disclosure

Written with Claude Code (Claude Opus 5.5), reviewed by me.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH / remote runtime: the target group is decided on the client and sent through the existing targetGroupId field. No new RPC field, no protocol change.
  • Folder workspaces: the rule reads only the tab layout, so it behaves the same for folders and git worktrees.
  • Docs: docs/site/content/docs/browser/overview.mdx describes the new placement.

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)

@pullfrog pullfrog 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.

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

  • Visible-browser link target selector — new findVisibleBrowserLinkTarget picks the focused group's browser, else the most recently focused one, from the worktree's effective layout.
  • Link routing — openHttpLink (terminal, markdown, editor, checks; local and remote) and the browser popup bridge pass that group as targetGroupId and focus it, so routed links join the on-screen browser pane; explicit new-tab actions are unchanged.
  • Docs and tests — overview.mdx documents the new placement; new selector unit tests, routing placement tests, popup bridge tests, and a real-store integration test cover the behavior.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

  • Last reviewed commit: c4793c34581e18ad13c741e1c5d1e7f6dc2020a3
  • Latest commit, not reviewed: 3bb8e21

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 802b6bab-8def-4a28-8e68-c154acf6c698

📥 Commits

Reviewing files that changed from the base of the PR and between e1557093a8bc11fa3150a843f200850c3ce9b68d and c4793c34581e18ad13c741e1c5d1e7f6dc2020a3.

📒 Files selected for processing (2)
  • src/renderer/src/hooks/ipc-events/browser-state-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/browser-state-open-link-profile.test.ts

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

Walkthrough

The change adds visible-browser target selection for Orca link routing. Local and remote HTTP routes, and IPC popup handling, can pass the selected group to browser-tab creation. Foreground routes focus the group, while background popups do not. Added tests cover target selection, routing behavior, and tab placement. Browser documentation describes the pane selection and fallback rules.

Priority: Low

Merge Risk: Minimal · up to c4793

Visible-browser link routing is ready to merge after normal checks; no actionable issue remains.

Security Architecture Review

Security architecture risk: 🔵 Low · up to c4793

Links now prefer a browser already visible in the same worktree. The reviewed paths preserve the opener’s browser session for popups, and no new cross-worktree access or security finding was established. Some remote-routing and failure cases remain unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The reviewed local placement path is bounded to the opener’s worktree: selection reads that worktree’s state, and tab creation receives the same worktree ID. Downstream remote enforcement was not established.

Trust Boundaries and Controls

  • observed — Popup URLs reach tab creation through the browser IPC handler. Placement does not substitute the destination browser’s profile: the handler supplies the opener’s profile and partition when its tab is present.

Resilience and Maintainability Implications

  • inferred — If a source page exists without its opener tab, popup creation falls back to the default browser profile. The same conditional behavior existed before this routing change; no PR-introduced increase in its exposure was established.

Hardening Proposals

  • proposed — Consider declining popup creation when the opener tab cannot be resolved, rather than allowing default-profile fallback; this would strengthen an existing session-ownership invariant.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the user impact, implementation, rationale, testing, remote behavior, and scope. However, it omits the required linked issue and required visual proof or an explicit N/A expla… Add the linked issue under “Linked Issue.” Add before/after screenshots or video under “Visual Proof,” or write “N/A” with a brief reason if visual proof is not applicable. Complete any remaining checklist items or explain why CI will cover…
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: routed links open in an existing visible browser pane.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the user impact, implementation, rationale, testing, remote behavior, and scope. However, it omits the required linked issue and required visual proof or an explicit N/A explanation for this behavior change.

Resolution

Add the linked issue under “Linked Issue.” Add before/after screenshots or video under “Visual Proof,” or write “N/A” with a brief reason if visual proof is not applicable. Complete any remaining checklist items or explain why CI will cover them.

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

@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch 3 times, most recently from 91b83df to a8f6ff5 Compare September 26, 2026 04:02

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Dropped the inert placementFixed field — findVisibleBrowserLinkTarget now returns BrowserLinkPlacement = { targetGroupId: string }; both call-site forwards, the routing test stub's opts type, and the three test assertions that referenced it are gone. This fully resolves the prior minor comment; no references to the field remain in the diff.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch 3 times, most recently from 322a728 to c4793c3 Compare September 28, 2026 03:13

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Rebased onto a newer main and reconciled its popup-anchor logic — browser-state-ipc-bridge.ts again resolves the opener's unified tab and forwards afterTabId/executionHostId, alongside the PR's targetGroupId placement.
  • The two mechanisms compose correctly: resolveUnifiedTabCreatePlacement keeps the visible-browser group but drops the anchor when the anchor's group differs, so a popup routed to the on-screen browser is not anchored to a source tab in another pane. The new test setup pins this (the splitWithVisibleBrowser assertion expects no afterTabId).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch from c4793c3 to f6f472a Compare September 29, 2026 03:07

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Dropped the inert placementFixed field — findVisibleBrowserLinkTarget and BrowserLinkPlacement now carry only targetGroupId; the selector's return sites, the routing test stub's opts type, and the four assertions that pinned the flag are gone. No reference to placementFixed remains anywhere in the tree, and the store consumes targetGroupId (browser-tab-actions.ts:163). This resolves the prior minor comment.
  • Rebased onto the current main — the branch was force-pushed to a fresh two-commit history on a newer base; the popup bridge still reconciles main's afterTabId/executionHostId anchor alongside the PR's targetGroupId placement.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Routes opened links to visible browser panes instead of new ones.

The PR appears safe to merge, with the previously reported remote-open focus behavior remaining as non-blocking feedback.

Findings

  1. P2 Failed opens still move focus ▶

Summary

The PR routes links to the active browser pane in the same worktree, while preserving the existing placement when no browser pane is visible.

  • Adds a selector for the visible browser pane and uses it for HTTP links and browser popups.
  • Adds placement tests and updates the browser documentation.

Reviews (8) · Last reviewed commit: "refactor(browser): drop the placement fl..."

Comment on lines +165 to +169
const placement = state ? findVisibleBrowserLinkTarget(state, worktreeId) : undefined
if (placement) {
// Why before: remote creation is async; focusing later could steal focus after the user moved on.
state?.focusGroup?.(worktreeId, placement.targetGroupId)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Failed opens still move focus For a remote link, this changes the focused pane before the asynchronous opener accepts the request. If the opener rejects, such as when the workspace route is unavailable, no tab opens but the user is left looking at the old browser page instead of the pane containing the link.

@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch 13 times, most recently from 378c554 to 9abdf9e Compare October 5, 2026 06:41
@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch 3 times, most recently from c14f683 to c1e3087 Compare October 6, 2026 19:30
@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch 10 times, most recently from 54f7e9e to fb5c41a Compare October 18, 2026 09:17
@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch 3 times, most recently from bcc4189 to 7a98ec0 Compare October 21, 2026 18:19
@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch 2 times, most recently from 5699a25 to e76d248 Compare October 23, 2026 12:48
Luca Critelli added 2 commits October 24, 2026 14:41
Links opened in Orca (terminal, markdown, editor, checks panel, remote
runtime/SSH, and target=_blank popups) now land as a new active tab in a
visible browser group of the same worktree, and focus moves there. With no
browser on screen, placement is unchanged.
Link placement only needs the target group; createBrowserTab has no
consumer for a pinned-placement flag.
@lucacri
lucacri force-pushed the lucacri/open-browser-in-side-panel branch from e76d248 to 1d47e70 Compare October 24, 2026 18:42
…acement state

Lets partial test stores (unset map entries, mutable fixture arrays) type-check against the widened link placement types.
@AmethystLiang

Copy link
Copy Markdown
Contributor

Was thinking about similar thing. Will review the PR soon

@AmethystLiang
AmethystLiang self-requested a review October 25, 2026 01:15
@AmethystLiang

Copy link
Copy Markdown
Contributor

@lucacri We’re incorporating your visible-browser pane selection and popup routing from this PR into our broader browser-link work in #32907, and I’ve credited you as a co-author on the integration commit.

The combined behavior reuses an exact page when it is already open in the same workspace, host, and browser profile; otherwise it opens a new tab in the focused or most recently used visible browser pane, or creates a split beside the source when no browser is visible. The broader PR also covers remote workspaces and protects against stale requests and focus changes while opening.

We’ll land the combined changes through #32907. Thanks for contributing this!

AmethystLiang added a commit that referenced this pull request Oct 25, 2026
Reuse matching pages within the same workspace, execution host and browser
profile. Otherwise open in the focused or most recently used visible browser,
or create a split beside the source when no browser is visible. Keep explicit
group placement and background/focus ownership protections.

Incorporate visible-browser selection and popup routing from #22686 into
#32907, including selector regression coverage.

Co-authored-by: Luca Critelli <[email protected]>
@AmethystLiang

Copy link
Copy Markdown
Contributor

Thanks @lucacri! Your changes are now incorporated into #32907, and you’re credited as a co-author on the integration commit. The combined PR should land soon, so I’m closing this one in favor of it. Thanks again for the contribution!

AmethystLiang added a commit that referenced this pull request Oct 25, 2026
Reuse matching pages within the same workspace, execution host and browser
profile. Otherwise open in the focused or most recently used visible browser,
or create a split beside the source when no browser is visible. Keep explicit
group placement and background/focus ownership protections.

Incorporate visible-browser selection and popup routing from #22686 into
#32907, including selector regression coverage.

Co-authored-by: Luca Critelli <[email protected]>
AmethystLiang added a commit that referenced this pull request Oct 25, 2026
Reuse matching pages within the same workspace, execution host and browser
profile. Otherwise open in the focused or most recently used visible browser,
or create a split beside the source when no browser is visible. Keep explicit
group placement and background/focus ownership protections.

Incorporate visible-browser selection and popup routing from #22686 into
#32907, including selector regression coverage.

Co-authored-by: Luca Critelli <[email protected]>
AmethystLiang added a commit that referenced this pull request Oct 25, 2026
Reuse matching pages within the same workspace, execution host and browser
profile. Otherwise open in the focused or most recently used visible browser,
or create a split beside the source when no browser is visible. Keep explicit
group placement and background/focus ownership protections.

Incorporate visible-browser selection and popup routing from #22686 into
#32907, including selector regression coverage.

Co-authored-by: Luca Critelli <[email protected]>
AmethystLiang added a commit that referenced this pull request Oct 25, 2026
* Open links beside their source and reuse matching browser pages

- Preserve source-group placement across terminal, chat, file, and runtime links
- Add explicit “Open in this group” actions with safe refusal handling
- Match browser pages by host, session, resource, and exact page identity

* Preserve file link ownership when opening beside source

* Isolate browser link sessions by workspace profile

* Wait for browser tabs to render before activating links

* Respect explicit group requests when opening detected files

* Preserve legacy link ownership when opening browser tabs

* Clean up unactivated browser tabs after failed link opens

* Reveal routed browser links without stealing focus

* Preserve browser profile reuse and foreground ownership during link open

* Prefer visible browser panes and reuse exact link destinations

Reuse matching pages within the same workspace, execution host and browser
profile. Otherwise open in the focused or most recently used visible browser,
or create a split beside the source when no browser is visible. Keep explicit
group placement and background/focus ownership protections.

Incorporate visible-browser selection and popup routing from #22686 into
#32907, including selector regression coverage.

Co-authored-by: Luca Critelli <[email protected]>

* Route browser links by workspace without reading global focus

* Validate SSH browser ownership before opening links

* fix branch file size limit

* fix(ci): track extracted browser link ratchet entries

* fix(test): follow source-aware browser link opening

---------

Co-authored-by: Luca Critelli <[email protected]>
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.

2 participants