[STG-1859] fix(cli): use exact DevToolsActivePort websocket path
Merged
SH
7mo ago+587+587+012345678901234567890123456789-253-253-012345678901234567890123456789
Summary
- move local CDP discovery into a dedicated module so the DevToolsActivePort behavior is directly testable
- reuse the exact
DevToolsActivePortwebsocket path forbrowse env local --auto-connect - reuse the same exact-path lookup for bare numeric CDP targets in
resolveWsTarget - avoid the extra speculative websocket verification pass on the file-backed discovery path
- add regression coverage for exact-path resolution, stale file cleanup, ambiguity, and fallback port probing
Root Cause
The CLI was reading DevToolsActivePort but then discarding the exact websocket path and probing generic endpoints first. On Chrome's remote-debugging approval flow that could trigger extra preflight requests before the real attach.
Validation
pnpm --filter @browserbasehq/stagehand gen-versionpnpm --filter @browserbasehq/stagehand build-dom-scriptspnpm --filter @browserbasehq/stagehand buildpnpm --filter @browserbasehq/browse-cli buildpnpm --filter @browserbasehq/browse-cli typecheckpnpm --filter @browserbasehq/browse-cli test
Summary by cubic
Fixes local CDP auto-connect by using the exact websocket path from DevToolsActivePort to avoid extra probes and speed up attach in Chrome’s approval flow. Addresses Linear STG-1859 and improves @browserbasehq/browse-cli for browse env local --auto-connect and bare port targets.
-
Bug Fixes
- Reuse the exact DevToolsActivePort websocket path for local auto-connect.
- Prefer exact-path resolution for bare numeric ports in
resolveWsTarget, then fall back to/json/version, then/devtools/browser. - Skip speculative websocket verification when a file provides the exact path.
- Clean up stale DevToolsActivePort files and return null on ambiguity.
-
Refactors
- Extracted local CDP discovery to
local-cdp-discovery.tswith tests for exact-path resolution, stale cleanup, ambiguity, and fallback probing.
- Extracted local CDP discovery to