const ws = new WebSocket('ws://localhost:9229/devtools/page/4F33F3F03E96FE32BDB194CBF92A9FA6')
let id = 0
const pending = new Map()
function send(method, params = {}) {
const msgId = ++id
return new Promise((resolve, reject) => {
pending.set(msgId, { resolve, reject })
ws.send(JSON.stringify({ id: msgId, method, params }))
})
}
async function ev(expr) {
const r = await send('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true })
return r.result.result.value
}
ws.addEventListener('open', async () => {
try {
const check = await ev(`(() => {
const gaugePath = document.querySelectorAll(".heap-gauge svg path")[1];
const stroke = getComputedStyle(gaugePath).stroke;
const cs = getComputedStyle(document.documentElement);
return {
gaugeStroke: stroke,
errVar: cs.getPropertyValue("--error-color").trim(),
accentVar: cs.getPropertyValue("--accent-color").trim(),
panelBg: cs.getPropertyValue("--panel-bg").trim(),
dashBorder: getComputedStyle(document.querySelector(".heap-dashboard")).borderLeftColor,
cardBg: getComputedStyle(document.querySelector(".heap-card")).backgroundColor
};
})()`)
console.log(JSON.stringify(check, null, 2))
} catch (e) { console.error('ERR', e.message) }
finally { ws.close() }
})
ws.addEventListener('message', ev => {
const msg = JSON.parse(ev.data)
if (msg.id && pending.has(msg.id)) { pending.get(msg.id).resolve(msg); pending.delete(msg.id) }
})