// 全页面巡检: 逐页打开收集 JS 异常 + 关键页截图 // 用法: node verify-pages.mjs import puppeteer from 'puppeteer-core' const browser = await puppeteer.launch({ executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', headless: 'new', args: ['--window-size=1440,900', '--enable-unsafe-swiftshader'], defaultViewport: { width: 1440, height: 900 }, }) const page = await browser.newPage() const errors = [] page.on('pageerror', e => errors.push(String(e).slice(0, 150))) page.on('console', m => { if (m.type() === 'error' && !m.text().includes('favicon')) errors.push('[console] ' + m.text().slice(0, 120)) }) const token = process.argv[2] const PAGES = [ ['dashboard', '/dashboard'], ['orders', '/orders'], ['quotations', '/quotations'], ['contracts', '/contracts'], ['financial', '/financial'], ['customers', '/customers'], ['aftersale', '/aftersale'], ['templates', '/templates'], ['combine', '/combine'], ['rendering', '/rendering'], ['ai_render', '/ai_render'], ['threed', '/threed'], ['measure', '/measure'], ['optimize', '/optimize'], ['cut_solution', '/cut_solution'], ['workshop', '/workshop'], ['printer', '/printer'], ['warehouse', '/warehouse'], ['products', '/products'], ['cost_estimate', '/cost_estimate'], ['devices', '/devices'], ['market', '/market'], ['chart', '/chart'], ['personal', '/personal'], ] for (const [name, path] of PAGES) { const before = errors.length await page.goto(`http://localhost:8000${path}?token=${encodeURIComponent(token)}`, { waitUntil: 'networkidle2' }) await new Promise(r => setTimeout(r, 900)) const add = errors.length - before console.log(`${add ? '✗' : '✓'} ${name}${add ? ` (${add} 个异常)` : ''}`) if (['financial', 'workshop', 'templates', 'cut_solution', 'report', 'chart'].includes(name)) { await page.screenshot({ path: `D:/Code/huamenchuang/shots/patrol-${name}.png` }) } } console.log(`\n==== 巡检完成: ${PAGES.length - (errors.length ? 1 : 0)} 页正常, 共 ${errors.length} 条异常 ====`) errors.slice(0, 8).forEach(e => console.log(' ', e)) await browser.close()