const fs = require('fs'); const path = require('path'); const {pathToFileURL} = require('url'); const {chromium} = require('playwright'); (async () => { const browser = await chromium.launch({headless: true}); try { const page = await browser.newPage({viewport: {width: 1100, height: 760}}); const errors = []; page.on('pageerror', error => errors.push(error.message)); await page.goto(pathToFileURL(path.resolve('report.html')).href, {waitUntil: 'load'}); const visibleImage = await page.locator('img').evaluateAll(images => images.some(image => { const box = image.getBoundingClientRect(); for (let node = image; node; node = node.parentElement) { const style = getComputedStyle(node); if (style.display === 'none' || style.visibility === 'hidden' || Number(style.opacity) === 0) return false; } return image.complete && image.naturalWidth >= 128 && image.naturalHeight >= 64 && box.width > 0 && box.height > 0; })); if (!visibleImage) throw new Error('report must visibly display its anomaly/center comparison image'); if (errors.length) throw new Error(errors.join(' | ')); fs.mkdirSync('/logs/verifier/visual-audit', {recursive: true}); await page.screenshot({path: '/logs/verifier/visual-audit/anomaly-report.png', fullPage: true}); } finally { await browser.close(); } })().catch(error => {console.error(error); process.exit(1);});