Skip to content

Commit 59cec74

Browse files
committed
fix(browser): clamp non-finite viewport dimensions
1 parent 0f72a04 commit 59cec74

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

extensions/browser/src/browser/pw-tools-core.snapshot.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ describe("pw-tools-core aria snapshot storage", () => {
203203
);
204204
});
205205

206+
it("clamps non-finite viewport dimensions to the minimum size", async () => {
207+
const page = { setViewportSize: vi.fn(async () => {}) };
208+
getPageForTargetId.mockResolvedValue(page);
209+
210+
const mod = await import("./pw-tools-core.snapshot.js");
211+
await mod.resizeViewportViaPlaywright({
212+
cdpUrl: "http://127.0.0.1:9222",
213+
targetId: "tab-1",
214+
width: Number.NaN,
215+
height: Number.POSITIVE_INFINITY,
216+
});
217+
218+
expect(page.setViewportSize).toHaveBeenCalledWith({ width: 1, height: 1 });
219+
});
220+
206221
it("stores role fallback metadata when backend markers are unavailable", async () => {
207222
const page = { id: "page-1" };
208223
const mod = await import("./pw-tools-core.snapshot.js");

extensions/browser/src/browser/pw-tools-core.snapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ export async function resizeViewportViaPlaywright(opts: {
455455
const page = await getPageForTargetId(opts);
456456
ensurePageState(page);
457457
await page.setViewportSize({
458-
width: Math.max(1, Math.floor(opts.width)),
459-
height: Math.max(1, Math.floor(opts.height)),
458+
width: resolveIntegerOption(opts.width, 1, { min: 1 }),
459+
height: resolveIntegerOption(opts.height, 1, { min: 1 }),
460460
});
461461
}
462462

0 commit comments

Comments
 (0)