← back to Cronjobs Viewer

5x/capture-console.js

20 lines

const pw = require('/Users/macstudio3/.npm-global/lib/node_modules/playwright');
const CHROME = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
(async () => {
  const b = await pw.chromium.launch({ executablePath: CHROME });
  const seen = [];
  for (let i = 0; i < 8; i++) {
    const ctx = await b.newContext({ httpCredentials: { username:'admin', password:'DW2024!' }});
    const p = await ctx.newPage();
    const local = [];
    p.on('console', m => { if (m.type() === 'error') local.push('CONSOLE: ' + m.text()); });
    p.on('pageerror', e => local.push('PAGEERROR: ' + e.message));
    await p.goto('http://127.0.0.1:9772/', { waitUntil:'networkidle', timeout:20000 }).catch(e=>local.push('GOTO: '+e.message));
    await p.waitForTimeout(1200);
    if (local.length) seen.push(`load#${i}: ` + local.join(' || '));
    await ctx.close();
  }
  await b.close();
  console.log(seen.length ? seen.join('\n') : 'NO ERRORS across 8 loads');
})();