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/cdp/target-factory.ts | |
| 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/cdp/target-factory.ts')
| -rw-r--r-- | src/cdp/target-factory.ts | 10 |
1 files changed, 5 insertions, 5 deletions
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<Result<ReadonlyAr const sessionForTarget = async (client: BrowserClient, targetId: string): Promise<Result<string, CdpError>> => { 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<Result<stri const ownership = client.ownership(); ownership.setHarnessWindow(targetId); ownership.add(targetId); - const win = await client.session().callBrowser("Browser.getWindowForTarget", { targetId }); - if (win.success) ownership.setHarnessWindowId(win.data.windowId); + const win = await getWindowId(client.session(), targetId); + if (win.success) ownership.setHarnessWindowId(win.data); return ok(targetId); }; |
