fix(browser): clamp non-finite viewport dimensions

This commit is contained in:
Peter Steinberger
2026-05-29 00:45:59 -04:00
parent 0f72a042d6
commit 59cec74d89
2 changed files with 17 additions and 2 deletions
@@ -203,6 +203,21 @@ describe("pw-tools-core aria snapshot storage", () => {
);
});
it("clamps non-finite viewport dimensions to the minimum size", async () => {
const page = { setViewportSize: vi.fn(async () => {}) };
getPageForTargetId.mockResolvedValue(page);
const mod = await import("./pw-tools-core.snapshot.js");
await mod.resizeViewportViaPlaywright({
cdpUrl: "http://127.0.0.1:9222",
targetId: "tab-1",
width: Number.NaN,
height: Number.POSITIVE_INFINITY,
});
expect(page.setViewportSize).toHaveBeenCalledWith({ width: 1, height: 1 });
});
it("stores role fallback metadata when backend markers are unavailable", async () => {
const page = { id: "page-1" };
const mod = await import("./pw-tools-core.snapshot.js");
@@ -455,8 +455,8 @@ export async function resizeViewportViaPlaywright(opts: {
const page = await getPageForTargetId(opts);
ensurePageState(page);
await page.setViewportSize({
width: Math.max(1, Math.floor(opts.width)),
height: Math.max(1, Math.floor(opts.height)),
width: resolveIntegerOption(opts.width, 1, { min: 1 }),
height: resolveIntegerOption(opts.height, 1, { min: 1 }),
});
}