// 09-04 R64.2 验证:账号列表「刷新」(更新)按钮去文字留图标 const CDP = 9223; const list = await fetch(`http://localhost:${CDP}/json`).then((r) => r.json()); const page = list.find((t) => t.type === 'page' && (t.url || '').includes('8900')) || list.find((t) => t.type === 'page'); if (!page) { console.log('ERR: no page'); process.exit(1); } const ws = new WebSocket(page.webSocketDebuggerUrl); let id = 0; const pending = new Map(); const send = (method, params = {}) => new Promise((res, rej) => { const i = ++id; pending.set(i, { res, rej }); ws.send(JSON.stringify({ id: i, method, params })); }); ws.onmessage = (e) => { const m = JSON.parse(e.data); if (m.id && pending.has(m.id)) { const p = pending.get(m.id); pending.delete(m.id); m.error ? p.rej(new Error(m.error.message)) : p.res(m.result); } }; await new Promise((r) => (ws.onopen = r)); const ev = async (expr) => { const r = await send('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true }); if (r.exceptionDetails) return { __err: (r.exceptionDetails.exception?.description || r.exceptionDetails.text).slice(0, 300) }; return r.result.value; }; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); await send('Page.enable'); await send('Runtime.enable'); await send('Network.enable'); await send('Network.setCacheDisabled', { cacheDisabled: true }); await send('Emulation.setDeviceMetricsOverride', { width: 860, height: 1000, deviceScaleFactor: 1, mobile: false }); const waitFor = async (expr, ms = 15000) => { const t0 = Date.now(); while (Date.now() - t0 < ms) { if (await ev(expr)) return true; await sleep(300); } return false; }; const fail = (m) => { console.log('FAIL@' + m); process.exit(1); }; const fs = await import('node:fs'); await send('Page.navigate', { url: `http://127.0.0.1:8900/?t=${Date.now()}#/accounts` }); if (!(await waitFor(`location.hash === '#/accounts' && !!document.querySelector('#accUpdate') && [...document.scripts].some((s) => (s.src || '').includes('data-pages.js?v=20260904n'))`, 15000))) fail('accounts route'); await sleep(500); const r = await ev(`(() => { const b = document.querySelector('#accUpdate'); if (!b) return { err: 'no #accUpdate' }; const text = (b.textContent || '').trim(); const svg = b.querySelector('svg'); const rect = b.getBoundingClientRect(); return { text, hasSvg: !!svg, svgViewBox: svg ? svg.getAttribute('viewBox') : null, w: Math.round(rect.width), h: Math.round(rect.height), title: b.getAttribute('title') }; })()`); console.log(JSON.stringify(r, null, 2)); await ev(`document.querySelector('#accUpdate').scrollIntoView({ block: 'center' })`); await sleep(200); // 截图按钮所在 toolbar const rect = await ev(`(() => { const el = document.querySelector('.acc-toolbar'); const r = el.getBoundingClientRect(); return { x: r.x, y: r.y, w: r.width, h: r.height }; })()`); if (rect && !rect.__err) { const shot = await send('Page.captureScreenshot', { format: 'png', clip: { x: Math.max(0, rect.x - 4), y: Math.max(0, rect.y - 4), width: Math.min(rect.w + 8, 1200), height: Math.min(rect.h + 8, 800), scale: 1 } }); fs.writeFileSync(`tmp/r64_acc_toolbar.png`, Buffer.from(shot.data, 'base64')); } const ok = r && !r.__err && r.text === '' && r.hasSvg; console.log(ok ? '\n=== PASS ===' : '\n=== CHECK ==='); ws.close(); process.exit(ok ? 0 : 1);