const fs = require('fs'); const { chromium } = require('playwright-core'); const OUT = 'd:\\AI文件夹\\预算报价\\_console_result.json'; const EDGE = 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe'; const URL_ = 'http://127.0.0.1:8931/AI快速报价_Demo2.optimizing.html'; (async () => { const logs = { console: [], pageerror: [], requestfailed: [] }; const profileDir = 'd:\\AI文件夹\\预算报价\\.edge-console-' + Date.now(); const ctx = await chromium.launchPersistentContext(profileDir, { executablePath: EDGE, headless: true, args: ['--no-sandbox', '--disable-gpu', '--disable-breakpad', '--disable-crash-reporter'] }); const page = ctx.pages()[0] || await ctx.newPage(); page.on('console', msg => { logs.console.push({ type: msg.type(), text: msg.text().slice(0, 500) }); }); page.on('pageerror', err => { logs.pageerror.push(String(err && err.message || err).slice(0, 500) + ' | ' + String(err && err.stack || '').slice(0, 800)); }); page.on('requestfailed', req => { logs.requestfailed.push(req.url().slice(0, 200) + ' :: ' + (req.failure() && req.failure().errorText)); }); page.on('response', res => { if (res.status() >= 400) logs.requestfailed.push('HTTP ' + res.status() + ' ' + res.url().slice(0, 200)); }); try { await page.goto(URL_, { waitUntil: 'load', timeout: 30000 }); await page.waitForTimeout(6000); // 尝试触发一次默认识别相关的初始化函数(若存在) try { await page.evaluate(() => { if (typeof qUpdateRuleDescription === 'function') { try { qUpdateRuleDescription(); } catch(e){} } }); } catch (e) {} await page.waitForTimeout(2000); logs.title = await page.title(); logs.ok = true; } catch (e) { logs.error = String(e).slice(0, 500); } fs.writeFileSync(OUT, JSON.stringify(logs, null, 2), 'utf8'); await ctx.close(); process.exit(0); })().catch(e => { try { fs.writeFileSync(OUT, JSON.stringify({ fatal: String(e).slice(0, 500) }), 'utf8'); } catch (_) {} process.exit(1); });