diff options
| author | amankumarsingh77 <amankumarsingh7702@gmail.com> | 2026-07-28 00:17:13 +0530 |
|---|---|---|
| committer | Aman Kumar <145339995+amankumarsingh77@users.noreply.github.com> | 2026-08-02 19:12:46 +0530 |
| commit | bfba73fa2f1373abd8a5a704c9c833d6fce1b44f (patch) | |
| tree | e684310863ef6d9aaa9a6bd3d4d3100d75ee9069 /src/domains/viewport.ts | |
| parent | 5cfa7ccc8f4082db111bc0186c5fa3d44b767ad3 (diff) | |
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) <noreply@anthropic.com>
Diffstat (limited to 'src/domains/viewport.ts')
| -rw-r--r-- | src/domains/viewport.ts | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/domains/viewport.ts b/src/domains/viewport.ts index 9e9ac07..e4ba5d5 100644 --- a/src/domains/viewport.ts +++ b/src/domains/viewport.ts @@ -1,6 +1,7 @@ import { Type } from "typebox"; -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 { cdpCall } from "./cdp-call"; const ViewportArgs = Type.Object({ width: Type.Integer({ minimum: 100, maximum: 8000, description: "Viewport CSS pixel width" }), @@ -22,13 +23,13 @@ export const viewportResizeTool = defineBrowserTool({ parameters: ViewportArgs, concurrency: "serialized", async handler(args, { client }): Promise<Result<ToolOk, ToolErr>> { - const r = await client.session().call("Emulation.setDeviceMetricsOverride", { + const r = await cdpCall(client, "Emulation.setDeviceMetricsOverride", { width: args.width, height: args.height, deviceScaleFactor: args.deviceScaleFactor ?? 1, mobile: false, }); - if (!r.success) return err({ kind: "cdp_error", message: r.error.message }); + if (!r.success) return r; return ok({ text: `Viewport set to ${args.width}x${args.height} @${args.deviceScaleFactor ?? 1}x`, details: { |
