// 本地验证:用系统 Chrome 无头打开页面,截图 + 打印控制台错误 + 游戏状态 const puppeteer = require("puppeteer-core"); (async () => { const url = process.argv[2] || "http://localhost:3210/"; const out = process.argv[3] || "/tmp/cs-shot.png"; const wait = Number(process.argv[4] || 6000); const browser = await puppeteer.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless: "new", args: [ "--no-sandbox", "--enable-unsafe-swiftshader", "--use-gl=angle", "--use-angle=swiftshader", "--disable-dev-shm-usage", "--window-size=1280,760", ], defaultViewport: { width: 1280, height: 720 }, }); const page = await browser.newPage(); const logs = []; page.on("console", (m) => logs.push(`[${m.type()}] ${m.text()}`)); page.on("pageerror", (e) => logs.push(`[pageerror] ${e.message}`)); page.on("requestfailed", (r) => logs.push(`[reqfail] ${r.url()} ${r.failure() && r.failure().errorText}`)); await page.goto(url, { waitUntil: "networkidle2" }); await new Promise((r) => setTimeout(r, wait)); await page.screenshot({ path: out }); const info = await page.evaluate(() => { const S = window.__CS; if (!S) return { ok: false, why: "no __CS" }; const r = { scene: S.scene, phase: S.phase, you: S.you, code: S.code, spectating: S.spectating, players: S.players.map((p) => ({ slot: p.slot, name: p.name, hp: p.hp, alive: p.alive, pos: p.pos.map((v) => +v.toFixed(2)), })), score: S.score, hp: S.hp, mag: S.mag, alive: S.alive, fps: S.fps, pos: S.body ? S.body.pos : null, particles: S.particles.length, canvas: [document.getElementById("gl").width, document.getElementById("gl").height], }; return r; }); console.log(JSON.stringify(info, null, 2)); if (logs.length) console.log("--- console ---\n" + logs.join("\n")); await browser.close(); })();