Files
homepage_relaunch/scripts/motion-shots.mjs
T
2026-09-18 18:28:28 +02:00

17 lines
760 B
JavaScript

import { chromium } from 'playwright';
/* Scrolls a target into view and captures it at several moments, to see a draw-in happen. */
const [,, url, prefix, selector, width = '1440', times = '150,700,1600,3200'] = process.argv;
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: Number(width), height: 900 } });
await page.goto(url, { waitUntil: 'networkidle' });
const el = page.locator(selector).first();
await el.scrollIntoViewIfNeeded();
const t0 = Date.now();
for (const t of times.split(',').map(Number)) {
const wait = t - (Date.now() - t0);
if (wait > 0) await page.waitForTimeout(wait);
await el.screenshot({ path: `${prefix}-${t}.png` });
}
await browser.close();
console.log('captured', selector);