Skip to content

Commit c050d25

Browse files
committed
Resets viewport to original size after mobile scan runs
1 parent 79d3cfa commit c050d25

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

  • .github/scanner-plugins/reflow-scan

.github/scanner-plugins/reflow-scan/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
export default async function reflowScan({ page, addFinding, url } = {}) {
22
console.log('reflow plugin');
3+
const originalViewport = page.viewportSize()
34
// Check for horizontal scrolling at 320x256 viewport
45
try {
5-
await page.setViewportSize({ width: 320, height: 256 });
6-
const scrollWidth = await page.evaluate(() => document.documentElement.scrollWidth);
7-
const clientWidth = await page.evaluate(() => document.documentElement.clientWidth);
6+
await page.setViewportSize({width: 320, height: 256})
7+
const scrollWidth = await page.evaluate(() => document.documentElement.scrollWidth)
8+
const clientWidth = await page.evaluate(() => document.documentElement.clientWidth)
89

910
// If horizontal scroll is required (with 1px tolerance for rounding)
1011
if (scrollWidth > clientWidth + 1) {
@@ -18,7 +19,12 @@ export default async function reflowScan({ page, addFinding, url } = {}) {
1819
})
1920
}
2021
} catch (e) {
21-
console.error('Error checking horizontal scroll:', e);
22+
console.error('Error checking horizontal scroll:', e)
23+
} finally {
24+
// Restore original viewport so subsequent scans (e.g. Axe) aren't affected
25+
if (originalViewport) {
26+
await page.setViewportSize(originalViewport)
27+
}
2228
}
2329
}
2430

0 commit comments

Comments
 (0)