#!/usr/bin/env node /** * Console error monitor for dashboard SPA — clicks all tabs */ const { chromium } = require('playwright'); const fs = require('fs'); const path = require('path'); const TARGET_URL = process.env.TARGET_URL || 'http://host.docker.internal:3003'; const REPORTS_DIR = process.env.REPORTS_DIR || path.join(__dirname, '..', 'reports'); (async () => { const browser = await chromium.launch({ headless: true, args: ['--no-sandbox'] }); const context = await browser.newContext({ viewport: { width: 1280, height: 720 } }); const page = await context.newPage(); const consoleErrors = []; const networkErrors = []; page.on('console', msg => { if (msg.type() === 'error' && !msg.text().includes('favicon')) consoleErrors.push(msg.text()); }); page.on('requestfailed', req => { const url = req.url(); if (!url.includes('favicon')) networkErrors.push(url + ' | ' + req.failure().errorText); }); console.log('Console error check for', TARGET_URL); await page.goto(TARGET_URL, { waitUntil: 'domcontentloaded', timeout: 30000 }); await page.waitForTimeout(2000); for (const tab of ['overview','agents','history','recommendations','heatmap','impact']) { await page.click(`button[onclick="switchTab('${tab}')"]`); await page.waitForTimeout(1000); } await page.waitForTimeout(1000); await browser.close(); console.log(''); console.log('═════════════════════════════════════════'); console.log(' Console Error Monitor — Dashboard'); console.log('═════════════════════════════════════════'); console.log(' Console errors:', consoleErrors.length); console.log(' Network errors:', networkErrors.length); if (consoleErrors.length > 0) consoleErrors.forEach(e => console.log(' ', e.slice(0, 120))); if (networkErrors.length > 0) networkErrors.forEach(e => console.log(' NET', e.slice(0, 120))); console.log('═════════════════════════════════════════'); fs.mkdirSync(REPORTS_DIR, { recursive: true }); fs.writeFileSync(path.join(REPORTS_DIR, 'console-errors-dashboard.json'), JSON.stringify({ url: TARGET_URL, consoleErrors, networkErrors, timestamp: new Date().toISOString() }, null, 2)); })();