diff options
| author | amankumarsingh77 <amankumarsingh7702@gmail.com> | 2026-07-27 01:17:32 +0530 |
|---|---|---|
| committer | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-08-02 19:12:46 +0530 |
| commit | 9e9bf2a3badb59d0ce5bdb47c4e9d09ffb259e69 (patch) | |
| tree | 602a6e33a98de62bf1f0c1d873eeb2676c650242 /src/profile | |
| parent | d1b57558ff40ef6d6b19ee7eff0a44f7f4a585f6 (diff) | |
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) <noreply@anthropic.com>
Diffstat (limited to 'src/profile')
| -rw-r--r-- | src/profile/bind.ts | 17 |
1 files changed, 6 insertions, 11 deletions
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(); |
