Skip to content

fix(browser): keep an agent on its own tab when the user picks or opens another - #36108

Merged
AmoabaKelvin merged 5 commits into
mainfrom
browser-use-new-tab
Oct 30, 2026
Merged

AmoabaKelvin merged 5 commits into
mainfrom
browser-use-new-tab

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​172 $\color{#cf222e}{\Huge{\mathbf{−}}}$​89 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83

ELI5

When an agent was using a browser tab and you opened or clicked another tab in the same workspace, the agent's next step went to your tab and took it over. Now the agent stays on its own tab while it works, and your tab is left alone.

What Changed

Before: the agent was on tab A. The user opened tab B with "+" (in any tab group of that workspace), and the agent's next goto, click or snapshot ran in tab B. A user reported the workspace as unusable while an agent ran.

After: the agent keeps working in tab A. Once tab A has had no agent command for the activity window (the same ~20 s that drives "An agent is using this page"), the user's last pick applies again, so a new "look at this page" request still starts from the tab the user has open.

Mechanism: commands without --page run on the bridge's active tab for the worktree. browser:activeTabChanged set that tab on every user select or create. Now a person's pick (that IPC, or a tab created over RPC by a paired phone or desktop) is held instead of applied while an agent is driving the current tab. The agent's own tab create and tab switch still move it right away.

The browser skill reference also tells agents to always pass --page <browserPageId>, taken from tab current or tab create, so agents that follow it never depend on the active tab at all.

Why

The bridge is where the wrong fact lived. It treated "the tab the user last selected" as "the tab the agent is working on". The skill change alone wouldn't fix it, because any agent that skips --page would still follow the user. Pinning per agent caller would need every caller to send its identity, including paired and remote ones. Reusing the existing agent-activity state fixes it without that.

Limitation: an agent that pauses longer than the activity window between unpinned steps can still follow a newer user pick. The --page skill rule covers that case.

Linked Issue

No GitHub issue. This came from a user's P0 report with a screen recording.

Visual Proof

N/A: nothing in the UI changed. These are real runs against a hidden dev build, driving the agent side with the orca CLI and opening the second tab the way the "+" button does.

Before (main):

--- agent step 1 (unpinned goto)
  tab 0 ACTIVE https://example.com/?agent-step-1
--- user opens a new tab
  tab 2 ACTIVE data:text/html,
--- agent step 2 (unpinned goto)
  tab 2 ACTIVE https://example.com/?agent-step-2   <- landed in the user's new tab

After (this branch):

--- agent step 1 (unpinned)
  tab 0 ACTIVE https://example.com/?fix-step-1
--- user opens a new tab
  tab 1        data:text/html,
--- agent step 2 (unpinned)
  tab 0 ACTIVE https://example.com/?fix-step-2      <- stays on the agent's tab
--- agent idle 22s, then a new unpinned command
  tab 1 ACTIVE https://example.com/?fix-step-3      <- follows the user's pick again
--- agent tab create, then unpinned goto
  tab 2 ACTIVE https://example.com/?fix-step-4      <- agent's own new tab

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

On macOS, a hidden dev build with the dev CLI ran the sequence above. New routing tests cover a user pick being held and then applied, and a tab created by a phone versus by an agent. Both fail with the hold removed.

AI Disclosure

Review

The hold lives in selectForPerson and applyHeldPersonSelections in agent-browser-bridge-tabs.ts. setActiveTab uses the RPC caller to tell an agent's tab create from a person's.

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-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Only main-process routing changed, so there's no platform code. Remote CLI agents use the same bridge on the host. Phones are paired-device callers, so a tab created on a phone no longer pulls an agent off its tab. There's no wire or contract change.

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)

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR's effects stay within browser-agent page routing and its CLI guidance.

Fix the gap after an agent tab switch before merging; the next command can still take over the user's tab.

Findings

  1. P1 Switched tabs remain unprotected ▶

Summary

Holds user tab selections while an agent uses the routed page, then applies them after activity expires.

  • Agent commands stay on their page while a person switches tabs.
  • The browser guide tells agents to pin a page for every command.

Acknowledged limitation: AmoabaKelvin explicitly noted that unpinned steps paused beyond the activity window can follow a newer user pick.

Reviews (1) · Last reviewed commit: "fix(browser): keep an agent on its own t..." · Reviewed by Greptile

if (owningWorktreeId) {
this.activeWebContentsPerWorktree.set(owningWorktreeId, wcId)
}
this.pointAgentAt(wcId, owningWorktreeId ?? undefined)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Switched tabs remain unprotected

After an agent switches from tab A to tab B, a user pick can still redirect its next command without --page. tabSwitch queues through enqueueCommand, so beginAgentCommand marks A, not B. pointAgentAt then routes commands to B without marking B as agent-used.

If the user selects C before the next agent command, selectForPerson sees B as idle and immediately routes to C. The agent's next navigation or click then runs on the user's tab. Keep B marked as agent-used after the switch so user picks are held during this gap.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in b5efcde. The agent's tab switch or tab create now marks the new tab as agent-used right away, so a pick made before its next command is held too. Covered by the new routing test, and checked live: agent switches to tab 1, the user opens a tab at once, and the next unpinned goto stays on tab 1.

@coderabbitai

coderabbitai Bot commented Oct 29, 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.

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
Walkthrough

Tab routing now distinguishes agent RPC selections from person selections. Person selections are held while an agent uses the current page and applied when it becomes idle, if the selected tab still exists. Routing updates the global selection and, when provided, the worktree selection. Browser guides show how to obtain and pass a browserPageId to page commands, explain page-targeting defaults, and update stale-reference recovery examples.

Priority: Normal

Merge Risk: Low · previous review 4dd72

The new browser guidance can produce argument errors for certain commands; correcting the documented command scope is localized.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary browser-tab routing fix.
Description check Passed The description is detailed and covers the user impact, mechanism, rationale, limitation, testing, compatibility considerations, and checklist. The Linked Issue section states that no GitHub issue exi…
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 is detailed and covers the user impact, mechanism, rationale, limitation, testing, compatibility considerations, and checklist. The Linked Issue section states that no GitHub issue exists, but the rest of the required template is substantially complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 9 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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.

@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: 3

🔇 Additional comments: 1
src/main/browser/agent-browser-bridge-tabs.ts-21-21: 1

21-21: Major · Functional Correctness · Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Keep a pending person selection when the agent switches tabs.

If a person selects tab B while the agent uses tab A, selectForPerson holds B. If the agent then creates or switches to tab C, pointAgentAt deletes B. After C becomes idle, unpinned commands still target C; the person's selection never takes effect. Route the agent to C immediately, but retain the pending person selection until it can apply or a later person selection replaces it. (raw.githubusercontent.com)


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: 8dcc5e9e-3f12-4bc2-8751-a0aa452cbcfa
Commits

Reviewing files that changed from the base of the PR and between c351825 and 71abcb4.

Files selected for processing: 9
  • skill-guides/orca-cli/references/browser.md
  • src/cli/bundled-skill-guides.ts
  • src/main/browser/agent-browser-bridge-queue.ts
  • src/main/browser/agent-browser-bridge-state.ts
  • src/main/browser/agent-browser-bridge-tab-routing.test.ts
  • src/main/browser/agent-browser-bridge-tabs.ts
  • src/main/browser/agent-browser-bridge-test-harness.ts
  • src/main/browser/browser-agent-activity.ts
  • src/main/browser/browser-manager-visibility.ts

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

@AmoabaKelvin

Copy link
Copy Markdown
Collaborator Author

On CodeRabbit's unverified note (held pick dropped when the agent switches tabs): fixed in b5efcde. The agent's switch no longer clears a held pick. Its new tab is marked as agent-used, so the pick waits until that tab goes idle and then applies. Covered by the new routing test.

@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: 3


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: f97d5a5e-2b84-4bb0-9628-658d8b05c9f8
Commits

Reviewing files that changed from the base of the PR and between 71abcb4 and b5efcde.

Files selected for processing: 5
  • skill-guides/orca-cli/references/browser.md
  • src/cli/bundled-skill-guides.ts
  • src/main/browser/agent-browser-bridge-lifecycle.ts
  • src/main/browser/agent-browser-bridge-tab-routing.test.ts
  • src/main/browser/agent-browser-bridge-tabs.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.

…ns another

Unpinned agent commands followed the user's UI tab selection, so opening a
new tab pulled the running agent into it. A person's pick now waits until
the agent's tab goes idle, and the browser skill tells agents to always
pass --page.
…s through it

An agent's tab switch or create now marks the new tab as agent-used, so a
user pick before its next command is held too. A held pick survives the
agent's switch and follows a process swap. The browser guide pins --page in
every example and describes where unpinned commands go.

@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

Caution

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

⚠️ Outside diff range comments (3)

Minor · Pass the page ID to the stale-reference recovery snapshot. · bundled-skill-guides.ts:879

src/cli/bundled-skill-guides.ts:879
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Pass the page ID to the stale-reference recovery snapshot.

The recovery line omits --page, while the same guide says to always pass it. After the 20-second idle window, the unpinned snapshot can capture the user's tab. Refs are scoped per tab, so a retry on the original tab can use refs from the wrong snapshot. Keep the original page ID on the recovery snapshot and on the retry.

Also generate the bundled guide with pnpm run generate:bundled-skill-guides. pnpm run verify:bundled-skill-guides only checks for drift.

🐛 Suggested fix
-- `browser_stale_ref`: run `ORCA snapshot --json` and retry with fresh refs.
+- `browser_stale_ref`: run `ORCA snapshot --page <browserPageId> --json` and retry with fresh refs on the same `--page`.

Apply the change in skill-guides/orca-cli/references/browser.md, then run pnpm run generate:bundled-skill-guides.

Minor · Pass the page ID to both recovery commands. · browser.md:55

skill-guides/orca-cli/references/browser.md:55
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Pass the page ID to both recovery commands.

When the pinned fill or type fails, the fallback omits --page. Orca then resolves each command through the worktree's current tab. After the agent tab becomes idle, that tab can be the user's selected tab. inserttext can therefore insert text into the user's focused field.

Suggested fix
-- If `fill` or `type` fails on a custom input, try `ORCA focus --element @e1 --json` then `ORCA inserttext --text "text" --json`.
+- If `fill` or `type` fails on a custom input, try `ORCA focus --page <browserPageId> --element @e1 --json` then `ORCA inserttext --page <browserPageId> --text "text" --json`.
Minor · Pass --page to the exec fallback. · browser.md:55

skill-guides/orca-cli/references/browser.md:55
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Pass --page to the exec fallback.

exec accepts and forwards --page. Without it, the bridge resolves the worktree's active tab. After the 20-second activity window, that tab can be the user's selected tab, so the fallback can run an unlisted browser action on the wrong page.

Suggested fix
-- Anything not listed above goes through `ORCA exec --command "<agent-browser command>"`.
+- Anything not listed above goes through `ORCA exec --page <browserPageId> --command "<agent-browser command>"`.

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: b4a82d80-2dd4-42cb-bb01-b059598a5274
Commits

Reviewing files that changed from the base of the PR and between b5efcde and 3be435a.

Files selected for processing: 1
  • src/cli/bundled-skill-guides.ts

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

Comment thread src/cli/bundled-skill-guides.ts Resolved
…guidance

Recovery and exec fallbacks now carry --page, the JSON paths include the result
envelope, and the guide says tab current reports the agent's tab while it is
busy, that tab list/current/create take no --page, and that --page is not
worktree-scoped without --worktree.
@AmoabaKelvin

Copy link
Copy Markdown
Collaborator Author

The three outside-diff findings from the last CodeRabbit review are fixed in f198a2f. The browser_stale_ref snapshot, the focus/inserttext fallback and the exec fallback all carry --page <browserPageId> now.

@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

Additional comments: 1
skill-guides/orca-cli/references/browser.md-56-56: 1

56-56: Minor · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Distinguish the routed tab from an explicitly targeted page.

An agent can operate on page B with --page while page A remains current. In that case, tab current reports A, not the page the agent is using. Clarify that the agent must retain B’s ID rather than recover it from tab current. Update the bundled guide too. (raw.githubusercontent.com)


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: 7cfdab24-6720-4c42-81c3-32481e29caec
Commits

Reviewing files that changed from the base of the PR and between 3be435a and f198a2f.

Files selected for processing: 2
  • skill-guides/orca-cli/references/browser.md
  • src/cli/bundled-skill-guides.ts

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

Both commands let --page override --index, so pinning them closed or switched to
the agent's own tab. The guide also says to keep the pinned ID for the task,
since tab current shows the routed tab.

@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: ad50f684-bed1-4567-8f34-a1d851b10d0e
Commits

Reviewing files that changed from the base of the PR and between f198a2f and 4dd7225.

Files selected for processing: 2
  • skill-guides/orca-cli/references/browser.md
  • src/cli/bundled-skill-guides.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.

Point agents at --help, which lists --page only on page-targeted commands.
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.

1 participant