From bfba73fa2f1373abd8a5a704c9c833d6fce1b44f Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 00:17:13 +0530 Subject: refactor(domains): share target resolution and CDP error mapping The ref-vs-x/y branch turned out to exist in one tool, not four; it is now one helper with tests covering the half-specified-coordinate and stale-ref cases. cdpCall folds the repeated cdp_error mapping at 24 active-session call sites; target-scoped callOnTarget/callBrowser sites are left alone. Co-Authored-By: Claude Opus 5 (1M context) --- src/domains/screenshot.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/domains/screenshot.ts') diff --git a/src/domains/screenshot.ts b/src/domains/screenshot.ts index e3b3615..c6cc87b 100644 --- a/src/domains/screenshot.ts +++ b/src/domains/screenshot.ts @@ -3,11 +3,12 @@ import { writeFile, rename } from "node:fs/promises"; import { Type } from "typebox"; import { Image, type ImageTheme, Text, truncateToWidth, visibleWidth } from "@mariozechner/pi-tui"; import type { BrowserClient } from "../client"; -import { type Result, err, ok } from "../util/result"; +import { type Result, ok } from "../util/result"; import { defineBrowserTool, type ToolErr, type ToolOk } from "../util/tool"; import { screenshotPath } from "../util/paths"; import { loadSharp } from "../util/sharp-shim"; import { safeJs } from "../util/js-template"; +import { cdpCall } from "./cdp-call"; const ScreenshotArgs = Type.Object({ fullPage: Type.Optional(Type.Boolean({ default: false, description: "Capture beyond viewport" })), @@ -29,12 +30,12 @@ const captureBase = async ( const format = args.format ?? "png"; const quality = args.quality ?? 80; const path = screenshotPath(client.namespace, format); - const r = await client.session().call("Page.captureScreenshot", { + const r = await cdpCall(client, "Page.captureScreenshot", { format, captureBeyondViewport: args.fullPage ?? false, ...(format === "jpeg" ? { quality } : {}), }); - if (!r.success) return err({ kind: "cdp_error", message: r.error.message }); + if (!r.success) return r; await writeFile(path, Buffer.from(r.data.data, "base64")); return ok({ path, format }); }; -- cgit v1.2.3