diff --git a/.changeset/bright-pages-shoot.md b/.changeset/bright-pages-shoot.md new file mode 100644 index 0000000000..9d92dc34dc --- /dev/null +++ b/.changeset/bright-pages-shoot.md @@ -0,0 +1,5 @@ +--- +"browse": patch +--- + +Omit unset screenshot options so Stagehand V4 accepts default CLI screenshots. diff --git a/packages/cli/src/lib/driver/commands/runtime.ts b/packages/cli/src/lib/driver/commands/runtime.ts index 106e1d12cf..fe65ca6e32 100644 --- a/packages/cli/src/lib/driver/commands/runtime.ts +++ b/packages/cli/src/lib/driver/commands/runtime.ts @@ -26,13 +26,13 @@ export const runtimeHandlers: DriverCommandHandlers = { .parse(params); const page = await manager.activePage(); const buffer = await page.screenshot({ - animations: options.animations, - caret: options.caret, - clip: options.clip, - fullPage: options.fullPage, - quality: options.quality, + ...(options.animations === undefined ? {} : { animations: options.animations }), + ...(options.caret === undefined ? {} : { caret: options.caret }), + ...(options.clip === undefined ? {} : { clip: options.clip }), + ...(options.fullPage === undefined ? {} : { fullPage: options.fullPage }), + ...(options.quality === undefined ? {} : { quality: options.quality }), timeout: 10_000, - type: options.type, + ...(options.type === undefined ? {} : { type: options.type }), }); if (options.path) { await fs.writeFile(options.path, buffer); diff --git a/packages/cli/tests/driver-commands.test.ts b/packages/cli/tests/driver-commands.test.ts index 6d47aa15ef..606135e22d 100644 --- a/packages/cli/tests/driver-commands.test.ts +++ b/packages/cli/tests/driver-commands.test.ts @@ -448,6 +448,36 @@ describe("driver commands", () => { expect(page.waitForTimeout).toHaveBeenCalledWith(100); }); + it("omits undefined screenshot options from V4 wire requests", async () => { + const page = { screenshot: vi.fn().mockResolvedValue(Buffer.from("image")) }; + const manager = { + activePage: async () => page, + } as unknown as Parameters>[0]; + + await expect(runtimeHandlers.screenshot!(manager, {})).resolves.toEqual({ + base64: Buffer.from("image").toString("base64"), + }); + expect(page.screenshot).toHaveBeenCalledWith({ timeout: 10_000 }); + + await runtimeHandlers.screenshot!(manager, { + animations: "disabled", + caret: "hide", + clip: { height: 200, width: 300, x: 10, y: 20 }, + fullPage: true, + quality: 80, + type: "jpeg", + }); + expect(page.screenshot).toHaveBeenLastCalledWith({ + animations: "disabled", + caret: "hide", + clip: { height: 200, width: 300, x: 10, y: 20 }, + fullPage: true, + quality: 80, + timeout: 10_000, + type: "jpeg", + }); + }); + it("accepts fractional viewport scale values", async () => { const daemonDir = await fs.mkdtemp(join(tmpdir(), "browse-viewport-scale-")); const previousDaemonDir = process.env.BROWSE_DAEMON_DIR;