/** * Runner for the JOB BOARD wrap probe. * * node dev/server.mjs 8080 * CHROME_PATH=/path/to/chrome node dev/jobboard-wrap-run.mjs */ import fs from 'node:fs'; import path from 'node:path'; import { launch, CDP } from './cdpshot.mjs'; const BASE = process.argv[2] || 'http://127.0.0.1:8080/dev/jobboard-wrap.html'; const OUT = path.resolve('dev/shots'); const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); fs.mkdirSync(OUT, { recursive: true }); const { url: wsUrl, kill } = await launch(BASE, 9401, 1280, 800); const cdp = new CDP(wsUrl); let bad = 0; try { await cdp.open(); await cdp.send('Runtime.enable'); await cdp.send('Page.enable'); let rep = null; const t0 = Date.now(); while (Date.now() - t0 < 120000) { try { const r = await cdp.send('Runtime.evaluate', { expression: 'window.__JB ? JSON.stringify(window.__JB) : null', returnByValue: true }); if (r.result?.value) { rep = JSON.parse(r.result.value); break; } } catch { /* still booting */ } await sleep(500); } if (!rep) { bad++; console.log('✘ TIMEOUT — the page never reported'); } else { const shot = await cdp.send('Page.captureScreenshot', { format: 'png' }); fs.writeFileSync(path.join(OUT, 'jb-wrap.png'), Buffer.from(shot.data, 'base64')); fs.writeFileSync(path.join(OUT, 'jb-wrap.json'), JSON.stringify(rep, null, 1)); if (rep.stage === 'FAILED' || (rep.errors && rep.errors.length)) bad++; console.log(bad ? '✘' : '✔', JSON.stringify(rep, null, 1).slice(0, 4000)); } } finally { cdp.close(); kill(); await sleep(400); } process.exitCode = bad ? 1 : 0;