import { WebSocket } from 'ws'; const list = await (await fetch('http://127.0.0.1:9222/json/list')).json(); const page = list.find(t => t.type === 'page'); const ws = new WebSocket(page.webSocketDebuggerUrl); let id=0; const pend=new Map(); const send=(m,p={})=>new Promise(r=>{const i=++id;pend.set(i,r);ws.send(JSON.stringify({id:i,method:m,params:p}));}); await new Promise(r=>ws.on('open',r)); ws.on('message',d=>{const m=JSON.parse(d);if(m.id&&pend.has(m.id)){pend.get(m.id)(m.result);pend.delete(m.id);}}); await send('Emulation.setDeviceMetricsOverride',{width:1400,height:900,deviceScaleFactor:2,mobile:false}); await send('Page.navigate',{url:'http://127.0.0.1:5173/'}); await new Promise(r=>setTimeout(r,5000)); const {result}=await send('Runtime.evaluate',{expression:`(()=>{ const ts=document.querySelector('[data-testid="comm-tabs"]'); const b=ts.getBoundingClientRect(); // 往上找所有祖先,列出它们的几何+圆角,看 tabstrip 住在谁里面 const out=[]; let e=ts; while(e && e!==document.documentElement){ const r=e.getBoundingClientRect(), cs=getComputedStyle(e); out.push({tag:e.tagName.toLowerCase()+'.'+(e.className||'').split(' ').slice(0,3).join('.'), x:Math.round(r.x),y:Math.round(r.y),w:Math.round(r.width),h:Math.round(r.height), radius:cs.borderRadius, overflow:cs.overflow, bg:cs.backgroundColor}); e=e.parentElement; } return JSON.stringify({tabstrip:{x:Math.round(b.x),w:Math.round(b.width),y:Math.round(b.y),h:Math.round(b.height)}, ancestors:out},null,1); })()`,returnByValue:true}); console.log(result?.value); ws.close();