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/profile/bind.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/profile') diff --git a/src/profile/bind.ts b/src/profile/bind.ts index 10b38a3..5fbac6f 100644 --- a/src/profile/bind.ts +++ b/src/profile/bind.ts @@ -19,7 +19,9 @@ */ import type { BrowserClient } from "../client"; +import { attachTo } from "../cdp/attach"; import { type CdpError, cdpError } from "../cdp/errors"; +import { getWindowId } from "../cdp/window"; import { type Result, err, ok } from "../util/result"; import { detectRunningBrowser, resolveBrowserExecutable } from "./browser-process"; import { openProfileWindow } from "./launch"; @@ -116,22 +118,15 @@ export const seedProfileWindow = async ( const ownership = client.ownership(); ownership.setHarnessWindow(seed.targetId); ownership.add(seed.targetId); - const win = await client.session().callBrowser("Browser.getWindowForTarget", { targetId: seed.targetId }); - if (win.success) { - const windowId = (win.data as { windowId?: number }).windowId; - if (typeof windowId === "number") ownership.setHarnessWindowId(windowId); - } + const win = await getWindowId(client.session(), seed.targetId); + if (win.success) ownership.setHarnessWindowId(win.data); // Blank the handshake page so the seed tab behaves like any other fresh tab, // then remove the sentinel file. Best-effort: a failure here costs nothing // beyond the placeholder page staying visible. - const attached = await client.session().callBrowser("Target.attachToTarget", { - targetId: seed.targetId, - flatten: true, - }); + const attached = await attachTo(client.session(), seed.targetId); if (attached.success) { - const sessionId = (attached.data as { sessionId: string }).sessionId; - await client.session().callOnTarget("Page.navigate", { url: "about:blank" }, sessionId); + await client.session().callOnTarget("Page.navigate", { url: "about:blank" }, attached.data); } await cleanup(); -- cgit v1.2.3