Skip to content

Remote CDP: 'tab not found' after reconnection — missing single-tab fallback #15989

@strelov1

Description

@strelov1

Problem

When using a remote CDP profile (e.g., Browserless), ensureTabAvailable() throws "tab not found" after the persistent Playwright connection drops and reconnects.

Reproduction scenario

  1. OpenClaw connects to a remote Browserless instance via connectOverCDP() → Chrome fix: add @lid format support and allowFrom wildcard handling #1 is created
  2. A tab is opened → lastTargetId = "abc123" is stored in profile state
  3. The persistent CDP WebSocket drops (network issue, Browserless session cleanup, etc.)
  4. onDisconnected fires → cached = null → Chrome fix: add @lid format support and allowFrom wildcard handling #1 is killed by Browserless
  5. Next browser request → connectBrowser() → fresh connectOverCDP() → Chrome Login fails with 'WebSocket Error (socket hang up)' ECONNRESET #2 (new process, no previous tabs)
  6. The AI agent passes targetId = "abc123" from the previous session
  7. resolveById("abc123") returns null — Chrome Login fails with 'WebSocket Error (socket hang up)' ECONNRESET #2 has no tab with that ID
  8. Error: "tab not found"

Root cause

In server-context.ts, ensureTabAvailable() has a graceful fallback for the extension driver when a stale targetId doesn't match and only one tab is available:

let chosen = targetId ? resolveById(targetId) : pickDefault();
if (!chosen && profile.driver === "extension" && candidates.length === 1) {
  // Recover by using the single attached tab
  chosen = candidates[0] ?? null;
}

This fallback does not apply to remote CDP profiles (!profile.cdpIsLoopback), even though the same stale-targetId scenario is common with remote browsers like Browserless where each new WebSocket connection spawns a fresh Chrome process.

Proposed fix

Extend the single-tab fallback to also cover remote CDP profiles:

if (!chosen && (profile.driver === "extension" || !profile.cdpIsLoopback) && candidates.length === 1) {
  chosen = candidates[0] ?? null;
}

The reasoning is the same as for extension relay: if an agent passes a stale/foreign targetId but we only have a single page available, recover by using that page instead of failing hard.

Environment

  • Remote CDP via Browserless v2 (Chrome image) on Fly.io
  • Persistent connectOverCDP() connection with TIMEOUT=-1
  • Connection drops trigger fresh Chrome creation (no session persistence in Browserless v2 + Playwright)

Related issues

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