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

Function connectToElectronPage

tooling/scripts/perf-desktop-runtime.mjs:367–391  ·  view source on GitHub ↗
(debugPort)

Source from the content-addressed store, hash-verified

365}
366
367async function connectToElectronPage(debugPort) {
368 const deadline = Date.now() + 20000
369 let lastError = null
370 while (Date.now() < deadline) {
371 try {
372 const targets = await httpGetJson(`http://127.0.0.1:${debugPort}/json/list`)
373 const page = targets.find(
374 (target) =>
375 target.type === 'page' &&
376 target.webSocketDebuggerUrl &&
377 typeof target.url === 'string' &&
378 (target.url.startsWith('file:') || target.url.includes('index.html'))
379 )
380 if (page) {
381 const client = new CdpClient(page.webSocketDebuggerUrl)
382 await client.connect()
383 return client
384 }
385 } catch (err) {
386 lastError = err
387 }
388 await sleep(100)
389 }
390 throw new Error(`Timed out waiting for Electron CDP page: ${lastError?.message ?? 'unknown error'}`)
391}
392
393async function evaluate(client, expression) {
394 const result = await client.send('Runtime.evaluate', {

Callers 1

mainFunction · 0.85

Calls 3

connectMethod · 0.95
httpGetJsonFunction · 0.70
sleepFunction · 0.70

Tested by

no test coverage detected