From 893a9d338ceb5d37aefece1df637c9a5888a120e Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 21:50:38 +0530 Subject: refactor: one CDP transport, not two MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit createCdpTransport was a second full WebSocket-to-Chrome implementation reachable only through client.ts's `?? createCdpTransport()` fallback, which production never took — every session and every automated test passes the daemon transport. transport.ts now holds only the CdpTransport interface, and the client requires a transport instead of inventing one. The "Session with given id not found" match that both transports carried becomes classifyRemoteError in cdp/errors.ts, next to the error kind it produces. test/manual/profile-concurrency-test.ts was the sole caller of the fallback: it drives its own Chrome on a private port. It now spawns a daemon per scenario with BU_CDP_WS set, and refuses to run when a daemon is already up, since that one is bound to a different browser. Co-Authored-By: Claude Opus 5 (1M context) --- src/cdp/daemon-transport.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/cdp/daemon-transport.ts') diff --git a/src/cdp/daemon-transport.ts b/src/cdp/daemon-transport.ts index 14f78c4..eb2bbd5 100644 --- a/src/cdp/daemon-transport.ts +++ b/src/cdp/daemon-transport.ts @@ -1,8 +1,8 @@ import { createConnection, type Socket } from "node:net"; import { createInterface } from "node:readline"; import { type Result, err, ok } from "../util/result"; -import { type CdpError, cdpError } from "../cdp/errors"; -import type { CdpTransport } from "../cdp/transport"; +import { type CdpError, cdpError, classifyRemoteError } from "../cdp/errors"; +import { DEFAULT_TIMEOUT_MS, type CdpTransport } from "../cdp/transport"; import type { CdpEvent } from "../cdp/types"; import { type Pending, makeEventQueue, makeOnClose, rejectAllPending, sendWithTimeout } from "./event-queue"; import { @@ -91,13 +91,7 @@ export const createDaemonTransport = (clientId: string): CdpTransport => { clearTimeout(p.timer); if (msg.error) { - p.resolve(err(cdpError( - msg.error.message.includes("Session with given id not found") - ? "session_not_found" - : "remote_error", - msg.error.message, - p.method, - ))); + p.resolve(err(cdpError(classifyRemoteError(msg.error.message), msg.error.message, p.method))); } else { p.resolve(ok(msg.result)); } @@ -149,7 +143,7 @@ export const createDaemonTransport = (clientId: string): CdpTransport => { params: Record, opts?: { sessionId?: string | null; timeoutMs?: number }, ): Promise> => { - const timeoutMs = opts?.timeoutMs ?? 15_000; + const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS; const sessionId = opts?.sessionId ?? null; const sock = socket; -- cgit v1.2.3