Skip to content

fix(tools): anchor untargeted tab resolution to the session's last navigated tab - #449

Open
wjl8636 wants to merge 1 commit into
Tencent:mainfrom
wjl8636:fix/anchor-default-tab-420
Open

wjl8636 wants to merge 1 commit into
Tencent:mainfrom
wjl8636:fix/anchor-default-tab-420

Conversation

@wjl8636

@wjl8636 wjl8636 commented Oct 14, 2026

Copy link
Copy Markdown

What

When a tool call does not specify tab_id, resolveVisibleTargetTab picked the Agent Window's live active tab on every call. The Agent Window holds several tabs — a user-opened tab or an extension popup can become the active one — so a session that navigated or observed a page could silently retarget the next untargeted call to a different document. Concretely (issue #420): after a cdp_extension_access_denied / re-navigate, bsk evaluate ran against an unrelated tab with no error, and the caller got no tab identity in the result to notice.

Why

This is a correctness / safety hazard for in-page agents: a script written for one page (fill forms, read values) runs in another, with no indication. The issue's Expected is explicit: "evaluate, click and fill in a session always target the session's own tab, the one its last navigate or observe reported."

What changed

  • SessionContext.lastTabId — the tab the session last navigated / observed / read.
  • handleNavigate and handleVomObservation record the resolved target in lastTabId after their scope checks pass.
  • resolveVisibleTargetTab (used by every untargeted tool call) anchors to lastTabId when set, and falls back to the live active tab only when the anchored tab has closed or left the Agent Window.

An explicit tab_id is unchanged and always wins. The CDP-accessible fallback in resolveCdpAccessibleTargetTab (restricted-URL recovery for observe/snapshot) is untouched.

How verified

  • 4 new unit tests in apps/extension/src/tools/__tests__/shared.test.ts: anchor wins over a drifted active tab; fallback to active when anchored tab closed; fallback when anchored tab left the window; active tab used when nothing anchored yet.
  • Full src/tools/__tests__ suite: 1183 passed, 196 skipped (e2e requiring a real browser), 0 failed.
  • tsc --noEmit clean.

Notes

…vigated tab

When a tool call does not specify tab_id, resolveVisibleTargetTab picked the
Agent Window's live active tab every time. The Agent Window holds several tabs
(a user-opened tab or extension popup can become active), so a session that
navigated or observed a page could silently retarget the next untargeted call
to a different document — evaluate ran against an unrelated page with no error,
and the caller got no tab identity to notice.

The session now remembers the tab it last navigated or observed
(SessionContext.lastTabId, set by handleNavigate and handleVomObservation) and
untargeted resolution anchors to it, falling back to the live active tab only
when the anchored tab has closed or left the Agent Window.

Fixes Tencent#420

This branch has not been deployed

No deployments
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.

[Bug] After a cdp_extension_access_denied failure and re-navigate, evaluate runs in a different tab of the same browser with no error

1 participant