diff options
| author | amankumarsingh77 <amankumarsingh7702@gmail.com> | 2026-07-27 23:26:50 +0530 |
|---|---|---|
| committer | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-08-02 19:12:46 +0530 |
| commit | 9f2f75dd9281153888776e5d39d4926655c15f2a (patch) | |
| tree | 89c23c8ad333b5096d39b661b142eaad544cf004 /src/domains/files.ts | |
| parent | 931576443dcb990761cb7e68e354465145f9292d (diff) | |
refactor(domains): drop CDP casts, share the box-model unwrap
ref-resolve.ts and snapshot.ts had the same box-model unwrap, both using
data.model! to work around an untyped response. Extracted to domains/box.ts;
the typed schema makes the assertions unnecessary. Both derived the centre
identically (quad corner + half the model width/height), so centreOf keeps
that derivation; the shared zero-size rejection moved into boxOf, and
snapshot keeps its own off-viewport (x/y < 0) filter.
evalInIsolatedTab now goes through evaluateJson with the tab's own sessionId
and a caller-supplied guard; both callers evaluate expressions ending in
JSON.stringify, so they pass isJsonText rather than a check that checks
nothing. Runtime.evaluate/callFunctionOn result casts in form.ts, forms.ts
and keyboard.ts are replaced by named guards over the in-page result shapes.
Runtime.callFunctionOn's params schema gained arguments/returnByValue/
awaitPromise/userGesture: four domain call sites legitimately pass them and
typebox's additionalProperties:true does not widen the static type, so the
params type was rejecting valid CDP fields. Params schemas are type-only
(only results are compiled), so this is a compile-time widening with no
runtime effect.
tsc is green again for both tsconfigs.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src/domains/files.ts')
| -rw-r--r-- | src/domains/files.ts | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/src/domains/files.ts b/src/domains/files.ts index d68d236..cf9393e 100644 --- a/src/domains/files.ts +++ b/src/domains/files.ts @@ -47,12 +47,9 @@ const tryCdpUpload = async ( ): Promise<Result<void, ToolErr>> => { const doc = await client.session().call("DOM.getDocument", { depth: -1 }); if (!doc.success) return err({ kind: "cdp_error", message: doc.error.message }); - // CDP boundary cast: DOM.getDocument returns { root: { nodeId: number } } - const root = (doc.data as { root: { nodeId: number } }).root; - const q = await client.session().call("DOM.querySelector", { nodeId: root.nodeId, selector }); + const q = await client.session().call("DOM.querySelector", { nodeId: doc.data.root.nodeId, selector }); if (!q.success) return err({ kind: "cdp_error", message: q.error.message }); - // CDP boundary cast: DOM.querySelector returns { nodeId: number } - const nodeId = (q.data as { nodeId: number }).nodeId; + const nodeId = q.data.nodeId; if (!nodeId) return err({ kind: "invalid_state", message: `Selector matched 0 file inputs: ${selector}` }); const set = await client.session().call("DOM.setFileInputFiles", { files: [filePath], nodeId }); if (!set.success) return err({ kind: "cdp_error", message: set.error.message }); @@ -214,10 +211,8 @@ export const printToPdfTool = defineBrowserTool({ preferCSSPageSize: true, }); if (!r.success) return err({ kind: "cdp_error", message: r.error.message }); - // CDP boundary cast: Page.printToPDF returns { data: string } (base64-encoded PDF) - const data = (r.data as { data: string }).data; const path = args.outputPath ?? pdfPath(client.namespace); - await writeFile(path, Buffer.from(data, "base64")); + await writeFile(path, Buffer.from(r.data.data, "base64")); return ok({ text: `PDF saved: ${path}`, details: { path } }); }, }); |
