fix(browser): recover stale CDP sessions - #112
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
Thanks Magnus — the diagnosis here is correct and it uncovered a real production problem. But we traced it one layer further and the root cause is on our side in Where the
|
|
Cloud-side fix is up: browser-use/cloud#5223. |
Problem
A flattened CDP target session can disappear while the browser-level WebSocket and page target remain usable. Reopening the root socket does not repair that target session, and an obsolete socket can still reject calls owned by a replacement socket.
Recovery also must not replay an arbitrary command on a different page. A rejected click, navigation, or evaluation is safe to retry only after reattaching the exact original target.
Change
connect()as ensure-connected, preserving a healthy socket and active target.-32001, serialize recovery, list targets at browser level, and reattach the exact original page.Reproduction
The tests use a local synthetic CDP WebSocket:
page-1and returnsession-1.CDP -32001: Session with given id not found.page-1inTarget.getTargets.page-1, domain restoration, and one successful retry.A second case removes
page-1before recovery and verifies that a side-effecting command is sent only once, no blank page is created, and no other target receives the command.Validation
bun testinpackages/bcode-browser: 21 pass, 8 environment-gated skipsbun typecheckinpackages/bcode-browsergit diff --check