From 9e9bf2a3badb59d0ce5bdb47c4e9d09ffb259e69 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Mon, 27 Jul 2026 01:17:32 +0530 Subject: refactor(cdp): extract attachTo, getWindowId, evaluateJson helpers Target.attachToTarget was decoded at 5 sites, Browser.getWindowForTarget at 5, and Runtime.evaluate unwrapped at another. Each is now one typed helper. Deletes the dead cdp/window-binding.ts. Co-Authored-By: Claude Opus 5 (1M context) --- src/cdp/target-factory.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/cdp/target-factory.ts') diff --git a/src/cdp/target-factory.ts b/src/cdp/target-factory.ts index fb22339..718a8d0 100644 --- a/src/cdp/target-factory.ts +++ b/src/cdp/target-factory.ts @@ -30,7 +30,9 @@ import { randomUUID } from "node:crypto"; import type { BrowserClient } from "../client"; import { type Result, err, ok } from "../util/result"; +import { attachTo } from "./attach"; import { type CdpError, cdpError } from "./errors"; +import { getWindowId } from "./window"; /** How long to wait for a window.open-spawned target to appear. */ const SPAWN_DEADLINE_MS = 8_000; @@ -63,9 +65,7 @@ const listPageTargets = async (client: BrowserClient): Promise> => { const current = client.current(); if (current?.targetId === targetId) return ok(current.sessionId); - const attached = await client.session().callBrowser("Target.attachToTarget", { targetId, flatten: true }); - if (!attached.success) return attached; - return ok(attached.data.sessionId); + return attachTo(client.session(), targetId); }; /** @@ -189,8 +189,8 @@ const createDedicatedWindow = async (client: BrowserClient): Promise