Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/cli/src/lib/driver/commands/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions packages/cli/tests/driver-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,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<NonNullable<(typeof runtimeHandlers)["screenshot"]>>[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;
Expand Down
Loading