--pin-tab over --cdp opens a throwaway tab before `tab <targetId>` binds, and close leaves it behind

Author: tryingETCreated Sep 23, 2026Updated Sep 27, 2026

Summary

When agent-browser is attached to a running browser with --cdp, a --pin-tab session that has no stored binding opens a fresh tab on attach, even when its first command is tab <targetId>, the command that selects the existing page to pin to. The session then binds to that page, and the fresh tab is never used. close on an external CDP connection disconnects without closing targets, so the unused tab stays in the browser. A caller that pins a fresh session to an existing page therefore leaves one blank tab behind each time. A session that restores a stored binding does not do this, and a session that goes on to use its fresh tab leaves nothing unused.

A second, narrower case works the same way. An unpinned session attaching to a browser whose only pages are internal (chrome://newtab/) creates an about:blank target, and close leaves that one too.

Code on current main (d01253d):

  • cli/src/native/actions.rs, apply_tab_binding_on_attach: with no stored binding and pin == true, it calls mgr.tab_new(None, None) ("A pinned session never implicitly adopts an existing tab: start it on a fresh one"). This runs during attach, before the command that carries the target id, and it does not look at that target.
  • cli/src/native/browser.rs, discover_and_attach_targets: Target.createTarget about:blank when no target passes should_track_target.
  • cli/src/native/browser.rs, close for an external connection: disconnects, and does not close the targets the session created.

Environment

  • agent-browser 0.35.1 and 0.38.0. 0.38.1 and current main differ from 0.38.0 in unrelated commits only.
  • Chromium 153.0.8010.47 on Linux, started separately with --remote-debugging-port=9222.
  • No AGENT_BROWSER_* environment variables, and no ~/.agent-browser state. A fresh --session name was used for every run.

Reproduction

bash
E=http://127.0.0.1:9222
pages() { curl -s $E/json/list | jq -c '[.[] | select(.type=="page") | {id: .id[0:6], url}]'; }

# a browser holding one https page
T=$(curl -s -X PUT "$E/json/new?https://example.com/" | jq -r .id)
pages                                                          # [{"id":"EDC90B","url":"https://example.com/"}]
agent-browser --cdp 9222 --session p1 --pin-tab tab "$T"       # ✓ Example Domain
pages                                                          # + {"id":"8ED510","url":"about:blank"}
agent-browser --cdp 9222 --session p1 --pin-tab snapshot -i --json
pages                                                          # unchanged
agent-browser --cdp 9222 --session p1 close
pages                                                          # about:blank 8ED510 is still there

Page targets after each step. Each row uses a fresh session on a browser set up with only the listed pages:

version starting pages session first command after 1st after close
0.35.1 / 0.38.0 https --pin-tab tab <https id> +1 about:blank stays
0.35.1 / 0.38.0 newtab, https --pin-tab tab <https id> +1 about:blank stays
0.35.1 / 0.38.0 newtab unpinned tab list +1 about:blank stays
0.35.1 / 0.38.0 https unpinned tab list +0 -
0.35.1 / 0.38.0 newtab, https unpinned tab list +0 -
0.35.1 / 0.38.0 about:blank unpinned tab list +0 -

Later commands in the same session add nothing. Three short fresh pinned sessions that each selected the same existing page (bind, snapshot -i --json, close) left three blank tabs.

Expected

When a fresh pinned session's first command is tab <targetId>, it should bind to that target directly, with no intermediate tab. The "never implicitly adopt an existing tab" rule is still honoured, because the caller named the tab explicitly.

A possible complement, offered as a proposal: if the tab that attach created was never used by the caller (it was bound only by the attach itself, then replaced by the caller's tab <targetId>, and never navigated), close on an external connection could close that one tab. It would still leave alone every other tab, including tabs the session created and used. Closing every session-created target would be a broader change, and those tabs may hold work someone meant to keep.

Impact

  • A read-only observer attaches to a tab another tool owns, pins to it with --pin-tab and tab <targetId>, and checks that the page count is unchanged before and after it runs. It sees a leak on every healthy run.
  • Long-running shared browsers accumulate blank tabs, one for each fresh pinned session that selected an existing page. The workaround is to identify the extra tab (the session's tab list shows it) and close it explicitly, which every caller has to remember to do.

Related

  • #1544: a headed launch leaves an untracked New Tab Page. Similar symptom, on launch rather than on --cdp attach.
  • #1790: a separate cross-session tab-ownership problem with --pin-tab, not this one.
  • #896: tab accumulation when several --session daemons share one --profile. A comment there describes a separate auto-connect variant. Neither involves explicit target selection.

Source: vercel-labs/agent-browser