← back to Dw Photo Capture
5x/tools/console-probe.cjs
34 lines
// Load each page in chromium/webkit/firefox, report console errors, pageerrors, failed requests, broken imgs.
const pwPath = process.env.PW || '/Users/macstudio3/Projects/carnegie-internal/node_modules/playwright';
const pw = require(pwPath);
const BASE = process.env.BASE || 'http://127.0.0.1:9987';
const PATHS = (process.env.PATHS || '/,/captures,/batch,/cam').split(',');
const ENGINES = (process.env.ENGINES || 'chromium,webkit,firefox').split(',');
(async () => {
const out = {}; let bad = 0;
for (const e of ENGINES) {
const b = await pw[e].launch();
for (const p of PATHS) {
const ctx = await b.newContext({ httpCredentials: { username: 'admin', password: 'DW2024!' } });
const page = await ctx.newPage();
const errs = [], reqf = [];
page.on('console', m => m.type() === 'error' && errs.push('console: ' + m.text() + ' @' + (m.location().url||'') + ':' + m.location().lineNumber));
page.on('pageerror', x => errs.push('pageerror: ' + x.message));
page.on('requestfailed', r => reqf.push(r.url() + ' ' + (r.failure() && r.failure().errorText)));
page.on('response', r => { if (r.status() >= 400 && !(r.status() === 401 && r.request().isNavigationRequest())) reqf.push(r.status() + ' ' + r.url()); });
const resp = await page.goto(BASE + p, { waitUntil: 'load', timeout: 20000 }).catch(x => { errs.push('goto: ' + x.message); return null; });
if (resp && resp.status() !== 200) errs.push('final document status ' + resp.status()); // the auth-challenge 401 is only OK if the retry lands 200
await page.waitForTimeout(2500);
const imgs = await page.$$eval('img', l => l.filter(i => i.complete && i.getAttribute('src') && !i.closest('[hidden]') && i.naturalWidth === 0).map(i => i.src.slice(0, 100))).catch(() => []);
const r = { errs, reqf, brokenImgs: imgs };
out[e + ' ' + p] = r;
const n = errs.length + reqf.length + imgs.length; bad += n;
console.log(`${n ? 'BAD ' : 'OK '} ${e.padEnd(8)} ${p.padEnd(10)} ${n ? JSON.stringify(r) : ''}`);
await ctx.close();
}
await b.close();
}
if (process.env.JSON) require('fs').writeFileSync(process.env.JSON, JSON.stringify(out, null, 2));
process.exit(bad ? 1 : 0);
})();