// Screenshot a page for an agent to look at. // node screenshot.mjs [width=1440] [height=900] [--full] import { chromium } from 'playwright'; const [url, out, width = '1440', height = '900'] = process.argv.slice(2).filter(a => !a.startsWith('--')); if (!url || !out) { console.error('usage: node screenshot.mjs [width] [height] [--full]'); process.exit(1); } // Full Chromium's new headless mode renders WebGL on the GPU; the default headless shell is software-only. const browser = await chromium.launch({ channel: 'chromium', args: ['--use-angle=metal', '--enable-gpu', '--ignore-gpu-blocklist'] }); const page = await browser.newPage({ viewport: { width: Number(width), height: Number(height) } }); const errors = []; page.on('pageerror', e => errors.push(e.message)); page.on('console', m => m.type() === 'error' && errors.push(m.text())); await page.goto(url, { waitUntil: 'networkidle' }); await page.waitForTimeout(1500); // let entrance animations settle await page.screenshot({ path: out, fullPage: process.argv.includes('--full') }); await browser.close(); console.log(errors.length ? `saved ${out}\nconsole errors:\n${errors.join('\n')}` : `saved ${out}`);