From 9f2ef1cf87251ce12f6b6432c48c6e7d2017b6b5 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Mon, 27 Jul 2026 00:48:45 +0530 Subject: refactor(cdp): make session.call generic over the command table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit call/callOnTarget/callBrowser now take a known method and return its decoded result type. The session is where unknown ends; transport keeps returning unknown. Removes the casts in session.ts and target-factory.ts, including the session's own internal Target.*/Browser.* calls, which now decode through the same path as the public call methods. Also completes two params-schema gaps in commands.ts surfaced by this migration: Target.createTarget was missing openerId and Runtime.evaluate was missing userGesture, both real CDP fields src/cdp/ already sends. tsc is red project-wide (6 errors, all in src/domains/) — the sanctioned state between Tasks 4 and 7. Co-Authored-By: Claude Opus 5 (1M context) --- src/cdp/target-factory.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/cdp/target-factory.ts') diff --git a/src/cdp/target-factory.ts b/src/cdp/target-factory.ts index 25c43a6..fb22339 100644 --- a/src/cdp/target-factory.ts +++ b/src/cdp/target-factory.ts @@ -56,8 +56,7 @@ type PageTarget = { const listPageTargets = async (client: BrowserClient): Promise, CdpError>> => { const r = await client.session().callBrowser("Target.getTargets"); if (!r.success) return r; - const data = r.data as { targetInfos: ReadonlyArray }; - return ok(data.targetInfos.filter((t) => t.type === "page")); + return ok(r.data.targetInfos.filter((t) => t.type === "page")); }; /** A CDP session id for driving `targetId`, reusing the active one when possible. */ @@ -66,7 +65,7 @@ const sessionForTarget = async (client: BrowserClient, targetId: string): Promis 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 as { sessionId: string }).sessionId); + return ok(attached.data.sessionId); }; /** @@ -92,8 +91,7 @@ const spawnTabViaOpener = async ( session.data, ); if (!opened.success) return opened; - const result = opened.data as { result?: { value?: unknown } }; - if (result.result?.value !== true) { + if (opened.data.result.value !== true) { return err(cdpError( "invalid_response", "the browser blocked window.open in the pinned profile's window — the page may have navigated away; retry, or run /browser-profile to re-seed", @@ -187,15 +185,12 @@ const ensureHarnessWindowUncoordinated = async ( const createDedicatedWindow = async (client: BrowserClient): Promise> => { const created = await client.session().callBrowser("Target.createTarget", { url: "about:blank", newWindow: true }); if (!created.success) return created; - const { targetId } = created.data as { targetId: string }; + const { targetId } = created.data; const ownership = client.ownership(); ownership.setHarnessWindow(targetId); ownership.add(targetId); const win = await client.session().callBrowser("Browser.getWindowForTarget", { targetId }); - if (win.success) { - const windowId = (win.data as { windowId?: number }).windowId; - if (typeof windowId === "number") ownership.setHarnessWindowId(windowId); - } + if (win.success) ownership.setHarnessWindowId(win.data.windowId); return ok(targetId); }; @@ -215,7 +210,7 @@ export const openHarnessTab = async ( openerId: openerTargetId, }); if (!created.success) return created; - return ok((created.data as { targetId: string }).targetId); + return ok(created.data.targetId); })(); if (!spawned.success) return spawned; client.ownership().add(spawned.data); -- cgit v1.2.3