File size: 1,440 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);});