aboutsummaryrefslogtreecommitdiff
path: root/src/cdp/target-factory.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmail.com>2026-07-27 00:48:45 +0530
committerAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-08-02 19:12:46 +0530
commit9f2ef1cf87251ce12f6b6432c48c6e7d2017b6b5 (patch)
tree2fad3353b016a9a35a049a7250b58ab2d165b50e /src/cdp/target-factory.ts
parentae3a6dcdbe584a9131a514ea3d738abaec6460f3 (diff)
refactor(cdp): make session.call generic over the command table
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) <noreply@anthropic.com>
Diffstat (limited to 'src/cdp/target-factory.ts')
-rw-r--r--src/cdp/target-factory.ts17
1 files changed, 6 insertions, 11 deletions
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<Result<ReadonlyArray<PageTarget>, CdpError>> => {
const r = await client.session().callBrowser("Target.getTargets");
if (!r.success) return r;
- const data = r.data as { targetInfos: ReadonlyArray<PageTarget> };
- 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<Result<string, CdpError>> => {
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);