Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 1 lines 1.1 kB view raw
1import WebSocket from "ws"; import { get } from "http"; const getTargets = () => new Promise((resolve, reject) => { get("http://host.docker.internal:9222/json", { headers: { Host: "localhost" } }, (res) => { let data = ""; res.on("data", chunk => data += chunk); res.on("end", () => resolve(JSON.parse(data))); }).on("error", reject); }); const targets = await getTargets(); const page = targets[0]; const ws = new WebSocket("ws://host.docker.internal:9222/devtools/page/" + page.id, { headers: { Host: "localhost" } }); let id = 1; const send = (method, params = {}) => new Promise((resolve) => { const msgId = id++; ws.once("message", (data) => resolve(JSON.parse(data).result)); ws.send(JSON.stringify({ id: msgId, method, params })); }); ws.on("open", async () => { const result = await send("Runtime.evaluate", { expression: "const menuBtns = Array.from(document.querySelectorAll(\"[aria-label=\\"Menu Options\\"]\")); menuBtns[1].click(); \"clicked second Menu Options\"", returnByValue: true }); console.log(result.result.value); setTimeout(() => ws.close(), 1000); });