MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / connectPage

Function connectPage

tooling/scripts/sidebar-vim-smoke.mjs:125–137  ·  view source on GitHub ↗
(port)

Source from the content-addressed store, hash-verified

123 close() { this.ws?.terminate?.(); this.ws?.close() }
124}
125async function connectPage(port) {
126 const deadline = Date.now() + 20000
127 let lastErr = null
128 while (Date.now() < deadline) {
129 try {
130 const targets = await httpGetJson(`http://127.0.0.1:${port}/json/list`)
131 const page = targets.find((t) => t.type === 'page' && t.webSocketDebuggerUrl && (String(t.url).startsWith('file:') || String(t.url).includes('index.html')))
132 if (page) { const c = new Cdp(page.webSocketDebuggerUrl); await c.connect(); return c }
133 } catch (e) { lastErr = e }
134 await sleep(100)
135 }
136 throw new Error(`no CDP page: ${lastErr?.message ?? 'timeout'}`)
137}
138async function evaluate(client, expression) {
139 const r = await client.send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true })
140 if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description ?? r.exceptionDetails.text)

Callers 1

mainFunction · 0.85

Calls 3

connectMethod · 0.95
httpGetJsonFunction · 0.70
sleepFunction · 0.70

Tested by

no test coverage detected