SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
1.5 KB · 33 lines javascript
Raw Blame History
1// Visual check helper: node scripts/screenshot.mjs <baseUrl> <outDir> [paths...]2// Uses a locally installed Playwright (resolved from PLAYWRIGHT_MODULE or the default require path).3import { createRequire } from 'node:module';4import { mkdirSync } from 'node:fs';5import path from 'node:path';67const require = createRequire(import.meta.url);8const pwPath = process.env.PLAYWRIGHT_MODULE ?? 'playwright';9const { chromium } = require(pwPath);1011const [base = 'http://localhost:3000', out = '/tmp/ri-shots', ...paths] = process.argv.slice(2);12const routes = paths.length ? paths : ['/', '/markets', '/markets/pokemon', '/rareindex', '/explore', '/sales', '/data'];13mkdirSync(out, { recursive: true });1415const browser = await chromium.launch();16for (const [label, viewport, theme] of [17  ['desktop-light', { width: 1440, height: 900 }, 'light'],18  ['desktop-dark', { width: 1440, height: 900 }, 'dark'],19  ['mobile-light', { width: 390, height: 844 }, 'light'],20]) {21  const ctx = await browser.newContext({ viewport, deviceScaleFactor: 1, colorScheme: theme });22  await ctx.addInitScript((t) => localStorage.setItem('ri-theme', t), theme);23  const page = await ctx.newPage();24  for (const r of routes) {25    await page.goto(base + r, { waitUntil: 'networkidle', timeout: 120_000 });26    const file = path.join(out, `${label}${r === '/' ? '-home' : r.replace(/[^a-z0-9]+/gi, '-')}.png`);27    await page.screenshot({ path: file, fullPage: true });28    console.log('saved', file);29  }30  await ctx.close();31}32await browser.close();33