Skip to content

[Bug]: connectOverCDP never completes when a pre-existing page target stops answering CDP commands #42730

Closed as duplicate

Description

Version

playwright-core 1.63.0-alpha (bundled with @playwright/cli 0.1.18 and 0.1.19). Same symptom reported earlier on 1.60.0 in #41093.

Steps to reproduce

Reproduces with any Chromium/Edge started with a debugging port — no special page or proxy needed. The trigger is a page target that exists at connect time but no longer answers page-level CDP commands (e.g. an Edge sleeping tab or a hung renderer), so I suspend one renderer to make that state deterministic:

# 1. start a browser with remote debugging
msedge --headless=new --remote-debugging-port=9333 --user-data-dir=/tmp/repro about:blank &

# 2. suspend the renderer of ONE tab (Chromium: one renderer process per tab)
ps -eo pid,args | grep repro | grep "type=renderer"   # pick one pid
kill -STOP <renderer_pid>                             # Windows: pssuspend <pid>

# 3. this call never returns (unpatched client)
node -e "const{chromium}=require('playwright');chromium.connectOverCDP('http://127.0.0.1:9333',{timeout:15000}).then(b=>console.log('ok'))"
#   => Timeout 15000ms exceeded; call log stops at <ws connected>

# 4. resume that renderer
kill -CONT <renderer_pid>
#   => connectOverCDP returns in ~30 ms

Note TargetInfo.pid is not usable to locate the victim (it reports 0 in headless mode / before the renderer spawns), hence the process table lookup.

Expected behavior

connectOverCDP should return a browser object. A page that cannot be initialized should be reported as-is or skipped; at worst connect should fail with a clear error. It should not hang indefinitely.

Actual behavior

connectOverCDP never resolves (or expires when an explicit timeout is passed). The call log ends at <ws connected>, while browser-level CDP commands still answer when sent manually, which makes it look like a protocol/handshake problem.

Additional context

Root cause. Connect auto-attaches to every existing target and then awaits CRBrowser._waitForAllPagesToBeInitialized(), i.e. Promise.all([..._crPages].map(p => p._page.waitForInitializedOrError())). For the frozen page, Page.enable, Page.getFrameTree, Log.enable, Runtime.enable and Runtime.runIfWaitingForDebugger are sent but never answered, so that promise never settles.

Diagnostic signature. Pairing sent/answered CDP ids on the browser session: page-level commands for the stuck target get no reply for 30 s+, while browser-level commands answer immediately.

One bad tab poisons the whole connect (3-tab browser, 4 renderer processes, 1 suspended):

check result
Target.getTargets (browser-level) OK, 3 targets
Runtime.evaluate on the suspended tab TIMEOUT
Runtime.evaluate on the other two tabs "tabA|1+1=2", "tabB|1+1=2"
connectOverCDP (unpatched) FAILED after 15015 ms
connectOverCDP after kill -CONT CONNECTED in 31 ms

Related, but different await. #41093 shows the identical symptom on Edge 148 (WS connects, then hangs) and was closed as NOT_PLANNED for lack of a reliable repro; that reporter mentioned tabs "stuck due to loading errors or had gone into sleep mode" and that reloading every tab fixed it. PR #41128 addressed a page stuck on its first navigation commit, which is not the await that hangs here. #41397 (prerender activation) is a different mechanism again.

Why it matters for attach. In the everyday case — attaching to a user's own browser with many tabs — a single sleeping/hung tab makes every subsequent playwright-cli attach fail with Daemon process exited with code 1, until the user manually reloads/closes that tab.

Local workaround (not proposed as the fix): after the auto-attach sweep, drop _crPages entries whose targetId is absent from Target.getTargets, and race the initialization wait with a timeout. Connect then succeeds at the cost of a fixed 10 s delay; a targeted "skip/flag unresponsive page targets" approach would be better.

Environment

  System:
    OS: Linux 7.0 openSUSE Tumbleweed 20260430
    CPU: (20) x64 AMD Ryzen AI 9 H 365 w/ Radeon 880M
    Memory: 13.23 GB / 27.02 GB
  Binaries:
    Node: 24.14.1 - /usr/bin/node
    npm: 11.11.0 - /usr/bin/npm
  npmPackages:
    @playwright/cli: 0.1.18 (unpatched) / 0.1.19 (patched workaround tested)
    playwright-core: 1.63.0-alpha (bundled)
  Browsers:
    Microsoft Edge 148.0.3967.54 launched with --remote-debugging-port=9333

Activity

  1. github-actions commented on Sep 15, 2026

    @github-actions
    Contributor

    Hi, I'm the Playwright bot and I took a first look at this.

    Reproduced on tip-of-tree (npm playwright@next, 1.64.0-alpha-2026-09-15), Chrome 152.0.7977.82 headless on Linux. Your analysis holds up: one page target that stops answering page-level CDP is enough to fail the whole connectOverCDP, even though the browser session and every other tab keep answering. With a suspended renderer the call fails with the default 30s timeout (or whatever explicit timeout you pass), and the call log ends at <ws connected> exactly as you described. SIGCONT on that one renderer, and the same connect succeeds in 47 ms.

    The hang is where you say it is — CRBrowser.connect awaits _waitForAllPagesToBeInitialized() (crBrowser.ts:97), which is Promise.all over waitForInitializedOrError() for every auto-attached page, so a target whose renderer never replies to Page.enable/Runtime.enable blocks all of them. That's a different await from the first-navigation-commit case fixed in #41128, so this isn't covered by it.

    Repro I used (no Edge sleeping tab needed)
    google-chrome --headless=new --remote-debugging-port=9333 --user-data-dir=/tmp/repro about:blank &
    # open a second page over CDP so there are two page targets, then SIGSTOP the renderer
    # backing one of them (identify it by evaluating 1+1 on each /json/list page target —
    # the frozen one times out, the other answers).
    node -e "require('playwright').chromium.connectOverCDP('http://127.0.0.1:9333',{timeout:15000}).then(()=>console.log('ok'),e=>console.log(e.message))"
    browserType.connectOverCDP: Timeout 10000ms exceeded.
    Call log:
      - <ws preparing> retrieving websocket url from http://127.0.0.1:9333
      - <ws connecting> ws://127.0.0.1:9333/devtools/browser/0cb15f35-...
      - <ws connected> ws://127.0.0.1:9333/devtools/browser/0cb15f35-...
    
    What I ran
    • version: tip-of-tree playwright@next = playwright-core 1.64.0-alpha-2026-09-15 (your 1.63.0-alpha is the same code path)
    • browser: Chrome 152.0.7977.82, --headless=new, Linux (openSUSE not available to me; used the repo's CI Linux image)
    • 2 page targets + extension/UI renderers, exactly one page renderer SIGSTOPped
    • connectOverCDP with timeout: 15000 → FAILED after 15016 ms
    • connectOverCDP with no explicit timeout → FAILED after 30009 ms (default timeout, so it doesn't hang forever — but it never connects)
    • connectOverCDP after SIGCONT → CONNECTED in 47 ms
    • control: suspending a non-page (extension/UI) renderer → CONNECTED in 47 ms, so it really is the page target that poisons it
    • while suspended: /json/list and Runtime.evaluate on the other page target answered immediately

    Chromium-only by construction — _waitForAllPagesToBeInitialized is on the CDP connect path, so there's nothing to compare against in firefox/webkit.

    Triaged on Linux by the Playwright bot - agent run

  2. Om-singhaI commented on Sep 18, 2026

    @Om-singhaI
    Contributor

    This looks like the same hang as #41093. That one and #41128 were closed because there was no reliable repro and only one report. This issue has both: freezing one renderer with kill -STOP hangs connectOverCDP every time, and the bot reproduced it on tip of tree. The #41093 reporter also said some of their tabs had gone into sleep mode, which is this mechanism rather than a navigation that never committed.

    It's a different await from #41128, though. The frozen renderer never answers the CDP commands in FrameSession._initialize, so racing against the initial empty page wouldn't help here.

    Would you take a fix that stops connectOverCDP from waiting on a page that was already open and never finishes initializing? I can put it together with a test that freezes one target through a CDP proxy.

  3. ZhongYic00 commented on Sep 20, 2026

    @ZhongYic00
    Author

    Yes, please go ahead om singhal (@Om-singhaI), and thanks for linking it back to #41093.

    The principle I'd pin: gate nothing, cancel nothing. Connect stops waiting on pre-existing pages, but their init keeps running and completes on its own when the sleeping tab wakes, no re-attach needed.

    That gives three invariants worth stating in the PR:

    1. Judge "unresponsive" by no CDP response within ~1-2 s, not by init completion, so slow-but-alive pages only ever degrade gracefully. This is the same trade-off fix(chromium): do not hang connectOverCDP on a page stuck loading #41128 already accepted, and the "risky change" concern is exactly why [Bug]: connect_over_cdp() hangs after <ws connected> with Microsoft Edge 148 on Windows #41093 was parked.
    2. context.pages() stays a complete snapshot. Unresponsive pages are listed immediately, with no new events or public state API; their commands just hit per-action timeouts. One small ask: make that timeout's call log hint at the likely cause (suspended or discarded target).
    3. Close targets that vanish between auto-attach and init instead of leaving zombie entries in pages(), and apply all of this per auto-attached target: a frozen OOPIF renderer hangs page init just like a frozen main frame.
  4. alexnayko commented on Oct 22, 2026

    @alexnayko

    Additional standalone-client evidence from October 22, 2026, after recovering one failed page still left whole-browser attach unavailable.

    Environment:

    • Linux, Node 22.22.1
    • Chromium 154.0.8037.57 behind an authenticated CDP gateway
    • @playwright/cli 0.1.15, bundled playwright-core 1.62.0-alpha-2026-06-29
    • One long-running shared browser, with existing page and iframe targets

    What I verified:

    1. Running the already-cached CLI directly with Node, without npx/npm, still fails after 31.36 seconds: daemon exits 1, Timeout 30000ms exceeded, call log ends at <ws connected>. This failure does not require the npm engine-version warning seen in the original launch.
    2. Standalone chromium.connectOverCDP(endpoint, {headers, timeout: 10000}) also times out. No application wrapper is necessary.
    3. A command/reply pairing of the protocol stream recorded 479 commands sent, 441 replies, and 38 outstanding commands on exactly four attached sessions: two page targets and two iframe targets.
    4. Both page sessions left Page.enable, Page.getFrameTree, Log.enable, Page.setLifecycleEventsEnabled, Runtime.enable, Page.addScriptToEvaluateOnNewDocument, Network.enable, Emulation.setFocusEmulationEnabled, Emulation.setEmulatedMedia and Runtime.runIfWaitingForDebugger unanswered. Each iframe session left the equivalent batch unanswered, without the focus-emulation command.
    5. As an independent control immediately afterward, gateway discovery returned HTTP 200 and browser-level CDP answered. A new task-owned about:blank page answered Runtime.evaluate(1+1) and Page.enable in 25 ms. Only this control page was then closed.
    6. A separate raw Runtime.evaluate on one of the two blocking page targets also timed out after eight seconds. This target had answered earlier in the incident, so the browser state had changed during collection.

    The relevant distinction is that restoring a particular failed page is insufficient if other pre-existing page/iframe sessions still do not answer. Even a healthy replacement page and browser-level CDP do not establish that whole-browser attach works.

    This matches the existing all-pages-initialization blocker described here. The underlying renderer crash/freeze cause is still unknown; I have not attributed it to Playwright itself. No shared browser restart, mass tab cleanup, renderer suspension or local client patch was performed. Site names, target URLs, authentication data and page contents are omitted.

    Recovery checkpoint, October 22 (operator-reported)

    The operator independently confirmed my stale-target finding: the page that timed out in raw CDP above still did not answer Runtime.evaluate(1) within ten seconds, and the earlier replacement for the other service was no longer in the target list. Only that handed-off, hung page was closed with Target.closeTarget, which returned success: true.

    Two replacement service pages now return live, complete DOM state through raw Runtime.evaluate, according to the operator, and their exact target IDs were handed back to the active collector. I have not independently reprobed these new pages. The earlier 15:25 UTC handoff is superseded by this target-specific checkpoint.

    The other previously observed blocking page was intentionally left untouched. No unrelated target was closed or reloaded, and the shared browser was not restarted. Whole-browser Playwright attach has not been reverified, and neither global recovery nor a renderer-crash root cause is claimed. This is restoration of the specific raw-CDP continuation route, not verification of an attach fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions