Skip to content

Commit 316bd8f

Browse files
committed
Add scroll to capture lazy loaded elements
1 parent 868680d commit 316bd8f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"fastify": "^4.24.3",
3838
"form-data": "^4.0.0",
3939
"listr2": "^7.0.1",
40+
"scroll-to-bottomjs": "^1.1.0",
4041
"tsup": "^7.2.0",
4142
"which": "^4.0.0",
4243
"winston": "^3.10.0"

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/screenshot.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { chromium, firefox, webkit, Browser } from "@playwright/test"
22
import { Context, WebStaticConfig } from "../types.js"
33
import { delDir, ensureHttps } from "./utils.js"
4+
import scrollToBottom from 'scroll-to-bottomjs'
45

56
const BROWSER_CHROME = 'chrome';
67
const BROWSER_SAFARI = 'safari';
@@ -52,13 +53,15 @@ export async function captureScreenshots(ctx: Context, screenshots: WebStaticCon
5253
screenshot.url = ensureHttps(screenshot.url)
5354
}
5455
await page.goto(screenshot.url, pageOptions);
55-
await page.waitForTimeout(screenshot.waitForTimeout || 0)
56+
5657

5758
for (let k = 0; k < totalViewports; k++) {
5859
let { width, height } = ctx.webConfig.viewports[k];
5960
let ssName = `${browserName}-${width}x${height}-${screenshotId}.png`
6061
let ssPath = `screenshots/${screenshotId}/${ssName}.png`
6162
await page.setViewportSize({ width, height: height || MIN_RESOLUTION_HEIGHT })
63+
if (height === 0) await page.evaluate(scrollToBottom)
64+
await page.waitForTimeout(screenshot.waitForTimeout || 0)
6265
await page.screenshot({ path: ssPath, fullPage: height ? false: true });
6366

6467
let completed = (i == (totalBrowsers-1) && j == (totalScreenshots-1) && k == (totalViewports-1)) ? true : false;

0 commit comments

Comments
 (0)