← back to Rentv Promos

recap-v2/scripts/capture.mjs

59 lines

#!/usr/bin/env node
/* Capture live rentv-v1.agentabrams.com screenshots for the recap video.
   Uses httpCredentials (URL-embedded creds don't reach page fetch()). */
import { createRequire } from 'node:module';
import { mkdirSync } from 'node:fs';
const require = createRequire('/Users/macstudio3/Projects/consulting-rentv-com/node_modules/');
const { chromium } = require('playwright');

const BASE = 'https://rentv-v1.agentabrams.com';
const OUT = new URL('../media/captures/', import.meta.url).pathname;
mkdirSync(OUT, { recursive: true });

const SHOTS = [
  // [name, path, {full, theme, waitMs}]
  ['home',            '/',                        { full: true,  waitMs: 6000 }],
  ['article',         '/news/34236',              { full: true,  waitMs: 6000 }],
  ['review',          '/review',                  { full: true,  waitMs: 6000 }],
  ['markets',         '/markets',                 { full: true,  waitMs: 8000 }],
  ['cretalk',         '/cre-talk',                { full: true,  waitMs: 6000 }],
  ['versions',        '/versions',                { full: true,  waitMs: 4000 }],
  ['v-wire',          '/versions/wire.html',      { full: false, waitMs: 6000 }],
  ['v-broadsheet',    '/versions/broadsheet.html',{ full: false, waitMs: 6000 }],
  ['v-terminal',      '/versions/terminal.html',  { full: false, waitMs: 6000 }],
  ['v-magazine',      '/versions/magazine.html',  { full: false, waitMs: 6000 }],
  ['v-dashboard',     '/versions/dashboard.html', { full: false, waitMs: 6000 }],
  ['theme-midnight',  '/',                        { full: false, theme: 4, waitMs: 6000 }],
  ['theme-salmon',    '/',                        { full: false, theme: 2, waitMs: 6000 }],
  ['admin-index',     '/admin',                   { full: true,  waitMs: 5000 }],
  ['admin-command',   '/admin/command.html',      { full: false, waitMs: 6000 }],
  ['admin-kanban',    '/admin/kanban.html',       { full: false, waitMs: 6000 }],
  ['admin-analytics', '/admin/analytics.html',    { full: false, waitMs: 6000 }],
  ['blog',            '/blog',                    { full: true,  waitMs: 5000 }],
  ['publish',         '/admin/publish.html',      { full: false, waitMs: 6000 }],
];

const browser = await chromium.launch();
const ctx = await browser.newContext({
  httpCredentials: { username: 'admin', password: 'DW2024!' },
  viewport: { width: 1920, height: 1080 },
  deviceScaleFactor: 1,
});

for (const [name, path, opt] of SHOTS) {
  const page = await ctx.newPage();
  try {
    if (opt.theme !== undefined) {
      await page.addInitScript(t => localStorage.setItem('rentv-theme', String(t)), opt.theme);
    }
    await page.goto(BASE + path, { waitUntil: 'load', timeout: 45000 });
    await page.waitForTimeout(opt.waitMs || 5000);
    await page.screenshot({ path: `${OUT}${name}.png`, fullPage: !!opt.full });
    console.log('ok', name);
  } catch (e) {
    console.log('FAIL', name, e.message.split('\n')[0]);
  }
  await page.close();
}
await browser.close();