screenshot.mjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import puppeteer from 'puppeteer-core';
  2. import { fileURLToPath } from 'url';
  3. import path from 'path';
  4. const __dirname = path.dirname(fileURLToPath(import.meta.url));
  5. const files = [
  6. 'cover.html',
  7. 'p1-buddy.html',
  8. 'p2-kairos.html',
  9. 'p3-ultraplan.html',
  10. 'p4-coordinator.html',
  11. 'p5-commands.html',
  12. 'p6-bridge.html',
  13. 'p7-flags.html',
  14. ];
  15. async function main() {
  16. const browser = await puppeteer.launch({
  17. executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
  18. headless: true,
  19. args: ['--no-sandbox'],
  20. });
  21. for (const file of files) {
  22. const page = await browser.newPage();
  23. await page.setViewport({ width: 1080, height: 1440, deviceScaleFactor: 2 });
  24. const filePath = path.join(__dirname, file);
  25. await page.goto(`file://${filePath}`, { waitUntil: 'networkidle0', timeout: 15000 });
  26. await new Promise(r => setTimeout(r, 1000));
  27. const outName = file.replace('.html', '.png');
  28. await page.screenshot({
  29. path: path.join(__dirname, outName),
  30. type: 'png',
  31. });
  32. console.log(`Done: ${outName}`);
  33. await page.close();
  34. }
  35. await browser.close();
  36. console.log('All done!');
  37. }
  38. main().catch(e => { console.error(e); process.exit(1); });