Skip to content

fix: prevent CDP connect hang on browsers with discarded/frozen tabs#1080

Open
ChunHao-dev wants to merge 1 commit intovercel-labs:mainfrom
ChunHao-dev:fix/cdp-discarded-tab-hang
Open

fix: prevent CDP connect hang on browsers with discarded/frozen tabs#1080
ChunHao-dev wants to merge 1 commit intovercel-labs:mainfrom
ChunHao-dev:fix/cdp-discarded-tab-hang

Conversation

@ChunHao-dev
Copy link
Copy Markdown
Contributor

@ChunHao-dev ChunHao-dev commented Mar 30, 2026

Summary

Fix CDP connect hanging indefinitely on browsers with discarded/frozen tabs (Chrome Memory Saver).

Fixes #1036

Changes

  • Add 3-second timeout to enable_domains() call during initial CDP connection in discover_and_attach_targets()
  • If the first tab fails to respond (likely discarded/frozen with no renderer process), fall back to creating a new about:blank tab
  • All existing tabs remain visible in tab list (attached but not enabled); they get enabled lazily on tab switch

Test plan

  • cargo fmt --check
  • cargo clippy
  • cargo test — 565 passed, 0 failed ✅
  • Manual test: chrome://discards → Urgent Discard multiple tabs → agent-browser --cdp 9222 get title
    • Before: hangs indefinitely
    • After: completes in ~3s with fallback to new tab

Design decision

Fallback to a new tab after the first timeout rather than trying all tabs because:

  1. Target.getTargets order is not sorted by activity — there's no way to know which tab is more likely to be active, so trying them sequentially doesn't improve the odds
  2. Each timeout costs 3 seconds — with many discarded tabs, sequential retries would add up (e.g. 10 discarded tabs = 30s wait)
  3. Creating a new tab is instant and guaranteed to work — it always has a live renderer

A future improvement could use the /json/list HTTP endpoint (which returns tabs sorted by most recently active) to pick a better first candidate.

… on discarded tabs

When connecting via --cdp to a browser with discarded/frozen tabs
(Chrome Memory Saver), Page.enable hangs indefinitely because
discarded tabs have no renderer process to respond.

Add a 3-second timeout to the initial enable_domains call. If the
first tab fails to respond (likely discarded), fall back to creating
a new about:blank tab.

Fixes vercel-labs#1036
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 30, 2026

@ChunHao-dev is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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: CDP connect hangs on browsers with discarded/frozen tabs (Memory Saver)

1 participant