// 验证禁用态:置灰、全子元素禁点、点击弹 toast、UIKit 入场动画 import { spawn } from 'node:child_process'; import { mkdtempSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; const CHROME = 'C:/Users/QunLIn/.agent-browser/browsers/chrome-154.0.8037.92/chrome.exe'; const PORT = 9403; const URL_ = process.argv[2] || 'http://127.0.0.1:1313/comment.html'; const OUT = process.argv[3] || ''; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const userDir = mkdtempSync(join(tmpdir(), 'cdp-edoff3-')); const chrome = spawn(CHROME, [ '--headless=new', `--remote-debugging-port=${PORT}`, `--user-data-dir=${userDir}`, '--no-first-run', '--disable-gpu', '--window-size=1280,1400', 'about:blank', ], { stdio: 'ignore' }); try { for (let i = 0; i < 40; i++) { try { const r = await fetch(`http://127.0.0.1:${PORT}/json/version`); if (r.ok) break; } catch { /* */ } await sleep(300); } const tab = await (await fetch(`http://127.0.0.1:${PORT}/json/new?${encodeURIComponent(URL_)}`, { method: 'PUT' })).json(); const ws = new WebSocket(tab.webSocketDebuggerUrl); let id = 0; const pending = new Map(); ws.addEventListener('message', (ev) => { const m = JSON.parse(ev.data); if (m.id && pending.has(m.id)) { pending.get(m.id)(m); pending.delete(m.id); } }); await new Promise((res) => ws.addEventListener('open', res)); const send = (method, params = {}) => new Promise((res) => { const mid = ++id; pending.set(mid, res); ws.send(JSON.stringify({ id: mid, method, params })); }); const ev = async (expr) => { const r = await send('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true }); return r.result?.result?.value ?? r.result?.value ?? null; }; await send('Runtime.enable'); await send('Page.enable'); await sleep(9000); // 状态检查 console.log(await ev(`JSON.stringify({ bodySvcDown: document.body.classList.contains('atk-svc-down'), editorOpacity: getComputedStyle(document.querySelector('.atk-main-editor')).opacity, barAnim: document.getElementById('atk-editor-off-bar')?.className || null, barText: document.getElementById('atk-editor-off-bar')?.textContent?.trim()?.slice(0, 40) || null, humanHidden: (() => { const h = document.querySelector('.atk-human-box'); return h ? getComputedStyle(h).display === 'none' : '(未渲染)'; })(), })`)); // 坐标级真实点击编辑器工具栏区域(表情/预览按钮所在的一排) const pos = JSON.parse(await ev(`(() => { const ed = document.querySelector('.atk-main-editor'); const r = ed.getBoundingClientRect(); return JSON.stringify({ x: Math.round(r.x + r.width / 2), y: Math.round(r.top + 14) }); })()`)); await send('Input.dispatchMouseEvent', { type: 'mousePressed', x: pos.x, y: pos.y, button: 'left', clickCount: 1 }); await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: pos.x, y: pos.y, button: 'left', clickCount: 1 }); await sleep(600); console.log('点击后 toast:', await ev(`(() => { const t = document.getElementById('atk-svc-toast'); return t ? { text: t.textContent.trim().slice(0, 40), visible: getComputedStyle(t).opacity !== '0' } : null; })()`)); // 确认编辑器内没有任何输入被聚焦(真禁用) console.log('焦点仍在 body:', await ev('document.activeElement === document.body || document.activeElement === document.documentElement')); if (OUT) { const s = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(OUT, Buffer.from(s.result.data, 'base64')); } ws.close(); } catch (e) { console.error('ERROR', e.message); } finally { chrome.kill(); }