// Screencast each staged scene to webm (real-time, in-container).
import puppeteer from '/home/adom/project/node_modules/puppeteer-core/lib/esm/puppeteer/puppeteer-core.js';
const CHROME = process.env.CHROME || '/home/adom/.cache/puppeteer/chrome/linux-146.0.7680.76/chrome-linux64/chrome';
const SCENES = [
  { id: 'player',  secs: 15 },
  { id: 'verify',  secs: 14 },
  { id: 'history', secs: 16 },
  { id: 'outro',   secs: 10 },
];
const b = await puppeteer.launch({ executablePath: CHROME, headless: 'new',
  args: ['--no-sandbox','--disable-gpu','--hide-scrollbars','--font-render-hinting=none',
         '--disable-features=CalculateNativeWinOcclusion','--disable-backgrounding-occluded-windows',
         '--disable-renderer-backgrounding','--disable-background-timer-throttling','--force-color-profile=srgb'] });
for (const s of SCENES) {
  const p = await b.newPage();
  await p.setViewport({ width: 900, height: 620, deviceScaleFactor: 2 });
  await p.goto(`file:///tmp/ttsdemo/scenes/${s.id}.html`, { waitUntil: 'networkidle0', timeout: 10000 }).catch(()=>{});
  await new Promise(r => setTimeout(r, 600));   // settle fonts/first paint
  const rec = await p.screencast({ path: `/tmp/ttsdemo/raw/${s.id}.webm` });
  await new Promise(r => setTimeout(r, s.secs * 1000));
  await rec.stop();
  console.log('recorded', s.id, s.secs + 's');
  await p.close();
}
await b.close();
console.log('done');