diff options
| author | amankumarsingh77 <amankumarsingh7702@gmal.com> | 2026-05-02 16:34:39 +0530 |
|---|---|---|
| committer | amankumarsingh77 <amankumarsingh7702@gmal.com> | 2026-05-02 16:34:39 +0530 |
| commit | dc07a5157188c09b79487af8b47fbda51b6af7d6 (patch) | |
| tree | 64ea434fb12e72f7ad511cbd9963463085db849d /src/domains | |
| parent | 5664dc8f6f41e93a8c320d7084451e25f3d93438 (diff) | |
feat(domains): migrate viewport_resize
Diffstat (limited to 'src/domains')
| -rw-r--r-- | src/domains/viewport.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/domains/viewport.ts b/src/domains/viewport.ts new file mode 100644 index 0000000..015ac68 --- /dev/null +++ b/src/domains/viewport.ts @@ -0,0 +1,40 @@ +import { Type } from "typebox"; +import { type Result, err, ok } from "../util/result"; +import { defineBrowserTool, type ToolErr, type ToolOk } from "../util/tool"; + +const ViewportArgs = Type.Object({ + width: Type.Integer({ minimum: 100, maximum: 8000, description: "Viewport CSS pixel width" }), + height: Type.Integer({ minimum: 100, maximum: 8000, description: "Viewport CSS pixel height" }), + deviceScaleFactor: Type.Optional( + Type.Number({ minimum: 0.5, maximum: 4, default: 1, description: "Device pixel ratio" }), + ), +}); + +export const viewportResizeTool = defineBrowserTool({ + name: "browser_viewport_resize", + label: "Browser Viewport Resize", + description: "Override the viewport size and device pixel ratio for responsive testing.", + promptSnippet: "Resize the viewport (responsive testing)", + promptGuidelines: [ + "Width/height in CSS pixels (e.g., 375x667 for iPhone SE).", + "Pass deviceScaleFactor=2 to simulate retina displays.", + ], + parameters: ViewportArgs, + async handler(args, { client }): Promise<Result<ToolOk, ToolErr>> { + const r = await client.session().call("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 }); + return ok({ + text: `Viewport set to ${args.width}x${args.height} @${args.deviceScaleFactor ?? 1}x`, + details: { + width: args.width, + height: args.height, + deviceScaleFactor: args.deviceScaleFactor ?? 1, + }, + }); + }, +}); |
