From 330767d862458386e804bde240a1f0d7835b9b8e Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 20:25:38 +0530 Subject: refactor(cdp): strip comment noise Removes module banners, section dividers, and comments restating the code. Keeps one-line notes for the window.open/browserContextId constraint, the seed-tab claim, the unverifiable-pin reuse rule, the SeedTargetProvider rationale, the deliberate dialog retention, the discovery-time browser quirks, and the guarded CDP decoder assertion. Co-Authored-By: Claude Opus 5 (1M context) --- src/cdp/transport.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/cdp/transport.ts') diff --git a/src/cdp/transport.ts b/src/cdp/transport.ts index f3bcd16..33b9412 100644 --- a/src/cdp/transport.ts +++ b/src/cdp/transport.ts @@ -15,8 +15,6 @@ export type CdpTransport = { params: Record, opts?: { sessionId?: string | null; timeoutMs?: number }, ): Promise>; - // Returns the current event queue's iterator. After close()+reconnect, callers - // must re-call events() — the old iterator will have received done:true. events(): AsyncIterable; state(): "open" | "closed" | "connecting"; onClose(cb: () => void): () => void; @@ -107,16 +105,13 @@ export const createCdpTransport = (): CdpTransport => { clearTimeout(timer); ws = null; cleanup("WebSocket closed"); - // If onopen already settled the connect promise, this settle is a no-op - // (guarded by `settled`). cleanup() above still runs unconditionally so - // pending requests are rejected and the event queue is rotated. settle(err(cdpError("transport_closed", "CDP WebSocket closed"))); }; }); }, close(): Promise { if (ws) { - try { ws.close(1000, "Shutdown"); } catch { /* best effort */ } + try { ws.close(1000, "Shutdown"); } catch {} ws = null; } cleanup("close() called"); @@ -128,8 +123,7 @@ export const createCdpTransport = (): CdpTransport => { if (!ws || ws.readyState !== WebSocket.OPEN) { return Promise.resolve(err(cdpError("transport_closed", "Browser not connected. Is Chrome running?", method))); } - // Bind to a local const so the non-null is guaranteed even across microtasks - // between the readyState check and the send() call. + // Bind to a local const so the non-null holds across microtasks between the readyState check and send(). const sock = ws; const id = nextId++; const payload: Record = { id, method, params }; @@ -138,11 +132,7 @@ export const createCdpTransport = (): CdpTransport => { return sendWithTimeout(pending, id, method, timeoutMs, "CDP", () => sock.send(json)); }, events(): AsyncIterable { - // Single-consumer: each connection's event stream may be iterated by - // exactly one for-await loop. Calling events() multiple times returns - // the same iterable; the second consumer will silently steal events - // from the first. After a reconnect, the previous iterator is ended - // and callers must re-call events() to receive new events. + // Single-consumer: a second for-await loop over this iterable silently steals events from the first. return queue.iter; }, state(): "open" | "closed" | "connecting" { -- cgit v1.2.3