← back to Factory Floor

scripts/snap.mjs

18 lines

#!/usr/bin/env node
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const OUT = path.join(__dirname, '..', 'snapshot.png');

const { chromium } = await import('/Users/macstudio3/Projects/animals/node_modules/playwright/index.mjs');
const browser = await chromium.launch();
const ctx = await browser.newContext({ viewport: { width: 1600, height: 1100 }, deviceScaleFactor: 2 });
const page = await ctx.newPage();
await page.goto('http://127.0.0.1:9936', { waitUntil: 'domcontentloaded', timeout: 60000 });
// Wait until the bigred tile is actually rendered (means /api/state populated)
await page.waitForSelector('.bigred', { timeout: 90000 });
await page.waitForTimeout(1500);
await page.screenshot({ path: OUT, fullPage: true });
await browser.close();
console.log(`✓ ${OUT}`);