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: 430, height: 932, deviceScaleFactor: 2, mobile: true }); await send('Page.navigate', { url: 'http://127.0.0.1:5173/' }); await new Promise(r => setTimeout(r, 4500)); const { result } = await send('Runtime.evaluate', { expression: `(() => { const out = {}; const shell = document.querySelector('.narrow-shell'); const nav = document.querySelector('.narrow-nav'); const listEl = document.querySelector('.overflow-y-auto'); const r = e => { if(!e) return null; const b = e.getBoundingClientRect(); return {top:Math.round(b.top), bottom:Math.round(b.bottom), h:Math.round(b.height)}; }; out.viewport = {h: innerHeight}; out.shell = r(shell); out.nav = r(nav); out.navStyle = nav ? {position:getComputedStyle(nav).position, margin:getComputedStyle(nav).margin, flexShrink:getComputedStyle(nav).flexShrink} : null; out.scroller = r(listEl); out.shellDisplay = shell ? getComputedStyle(shell).display : null; return JSON.stringify(out, null, 1); })()`, returnByValue: true }); console.log(result?.value); ws.close();