17 lines
968 B
JavaScript
17 lines
968 B
JavaScript
// usage: node shot.mjs <page.html> <out.png> [waitMs] [w] [h] [clickSelector...]
|
|
import { createRequire } from 'module';
|
|
const require = createRequire('/home/pizza/.dsh/profiles/web/node_modules/');
|
|
const { chromium } = require('playwright-core');
|
|
const [,, page, out, wait='3000', w='1600', h='900', ...clicks] = process.argv;
|
|
const b = await chromium.launch({ executablePath: process.env.CHROME || undefined });
|
|
const p = await b.newPage({ viewport: { width: +w, height: +h } });
|
|
const errs = [];
|
|
p.on('pageerror', e => errs.push('pageerror: ' + e.message));
|
|
p.on('console', m => { if (m.type() === 'error') errs.push('console: ' + m.text()); });
|
|
await p.goto('http://127.0.0.1:8790/' + page);
|
|
await p.waitForTimeout(+wait);
|
|
for (const c of clicks) { try { await p.click(c, { timeout: 2000 }); await p.waitForTimeout(800); } catch (e) { errs.push('click failed: ' + c); } }
|
|
await p.screenshot({ path: out });
|
|
console.log(JSON.stringify({ errs }));
|
|
await b.close();
|