// Dev helper: node scripts/shot.mjs [width] [height] [steps.json] // steps: [{"click":"text=Trasa"},{"fill":["#q","x"]},{"wait":500},{"eval":"js"}] import { chromium } from 'playwright-core'; const [out, w = '1280', h = '800', stepsArg = '[]'] = process.argv.slice(2); const url = process.env.URL ?? 'http://localhost:4173/'; const browser = await chromium.launch(); const page = await browser.newPage({ viewport: { width: +w, height: +h }, locale: 'pl-PL' }); const logs = []; page.on('console', (m) => { if (['error', 'warning'].includes(m.type())) logs.push(`${m.type()}: ${m.text()}`); }); page.on('pageerror', (e) => logs.push(`pageerror: ${e.message}`)); await page.goto(url, { waitUntil: 'networkidle' }); for (const s of JSON.parse(stepsArg)) { if (s.click) await page.locator(s.click).first().click(); else if (s.fill) await page.locator(s.fill[0]).first().fill(s.fill[1]); else if (s.press) await page.keyboard.press(s.press); else if (s.wait) await page.waitForTimeout(s.wait); else if (s.eval) console.log('eval:', JSON.stringify(await page.evaluate(s.eval))); } await page.waitForTimeout(800); await page.screenshot({ path: out }); if (logs.length) console.log(logs.slice(0, 15).join('\n')); await browser.close();