import type { WebContents } from 'electron' const DEBUGGER_COMMAND_TIMEOUT_MS = 8_000 export async function sendDebuggerCommand( dbg: WebContents['debugger'], method: string, params: Record = {} ): Promise { let timeout: ReturnType | null = null try { return await Promise.race([ Promise.resolve().then(() => dbg.sendCommand(method, params)), new Promise((_, reject) => { timeout = setTimeout(() => { reject(new Error(`Timed out while running ${method}.`)) }, DEBUGGER_COMMAND_TIMEOUT_MS) }) ]) } finally { if (timeout) { clearTimeout(timeout) } } }