From 4b2080c841bfe5a15e2eeeff19629380a460f844 Mon Sep 17 00:00:00 2001 From: Shrey Pandya Date: Thu, 30 Jul 2026 14:46:35 -0700 Subject: [PATCH 1/2] fix(cli): omit undefined screenshot options --- .changeset/bright-pages-shoot.md | 5 ++++ .../cli/src/lib/driver/commands/runtime.ts | 12 ++++---- packages/cli/tests/driver-commands.test.ts | 30 +++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 .changeset/bright-pages-shoot.md 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 3a96c450a5..fc9120c067 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; From 0ee1ce5c1a109c01e5e8f0d90eafd487015eca65 Mon Sep 17 00:00:00 2001 From: Shrey Pandya Date: Sun, 9 Aug 2026 21:51:14 +0000 Subject: [PATCH 2/2] fix(cli): encode V4 screenshot bytes --- packages/cli/src/lib/driver/commands/runtime.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/lib/driver/commands/runtime.ts b/packages/cli/src/lib/driver/commands/runtime.ts index fc9120c067..fe65ca6e32 100644 --- a/packages/cli/src/lib/driver/commands/runtime.ts +++ b/packages/cli/src/lib/driver/commands/runtime.ts @@ -38,7 +38,7 @@ export const runtimeHandlers: DriverCommandHandlers = { await fs.writeFile(options.path, buffer); return { saved: options.path }; } - return { base64: buffer.toString("base64") }; + return { base64: Buffer.from(buffer).toString("base64") }; }, async viewport(manager, params) {