20 lines
1.0 KiB
JavaScript
20 lines
1.0 KiB
JavaScript
import { chromium } from 'playwright';
|
|
const [,, url, prefix, width = '1440', height = '900', max = '12'] = process.argv;
|
|
const browser = await chromium.launch();
|
|
const page = await browser.newPage({ viewport: { width: Number(width), height: Number(height) } });
|
|
await page.goto(url, { waitUntil: 'networkidle', timeout: 60000 });
|
|
// trigger lazy loading by scrolling through
|
|
const total = await page.evaluate(() => document.documentElement.scrollHeight);
|
|
for (let y = 0; y < total; y += 600) { await page.evaluate((y) => window.scrollTo(0, y), y); await page.waitForTimeout(150); }
|
|
await page.evaluate(() => window.scrollTo(0, 0));
|
|
await page.waitForTimeout(800);
|
|
const h = Number(height);
|
|
const n = Math.min(Number(max), Math.ceil(total / h));
|
|
for (let i = 0; i < n; i++) {
|
|
await page.evaluate((y) => window.scrollTo(0, y), i * h);
|
|
await page.waitForTimeout(700);
|
|
await page.screenshot({ path: `${prefix}-${String(i).padStart(2, '0')}.png`, fullPage: false });
|
|
}
|
|
console.log('total height', total, 'shots', n);
|
|
await browser.close();
|