`connect <port>` doesn't stick: next plain command relaunches a local browser and silently drops the CDP attach

Author: aniketsaurav18Created Sep 26, 2026Updated Sep 26, 2026

Summary

agent-browser connect 9222 reports success, but the very next command without an explicit connection flag runs against a fresh local headless browser instead of the attached one. The user is silently driving the wrong browser.

This contradicts the documented CDP Mode flow (README and docs/src/app/cdp-mode/page.mdx): "Connect once, then run commands without --cdp".

Reproduction (0.38.1, Linux, config with executablePath/args)

$ agent-browser connect 9222
[agent-browser] launched browser
✓ Done

$ agent-browser get url
about:blank        # expected: the attached browser's URL

$ agent-browser --cdp 9222 get url
https://...        # correct, per-command flag works

Mechanism

  1. connect <port> parses to a one-off {action: launch, cdpPort} (cli/src/commands.rs, connect arm). It attaches but records nothing persistent.
  2. Every later plain invocation merges the config file (executablePath, args) into flags (cli/src/flags.rs) and therefore sends a local launch envelope first (should_send_local_launch_config, cli/src/main.rs).
  3. In handle_launch_inner (cli/src/native/actions.rs) that envelope computes is_external == false vs was_external == true, so needs_relaunch is true and the daemon closes the CDP connection and relaunches local.

Related reports in the same family: #1621 (mirror image for auto-connect), #1939, #1742 / PR #1835.

Expected

An explicit attach persists for follow-up commands without a target, per the docs. Switching back to a local browser should require close first (consistent with the guidance added for #1359).

Workaround

Pass --cdp 9222 (or --auto-connect) on every command, ideally with a fresh --session since the default daemon may already be bound to its own browser.

Source: vercel-labs/agent-browser