import WebSocket from 'ws'; export interface DevToolsTarget { id: string; title: string; url: string; webSocketDebuggerUrl: string; type: string; } export interface CommandResult { success: boolean; result?: any; error?: string; message: string; } /** Options for targeting a specific Electron window */ export interface WindowTargetOptions { /** CDP target ID (exact match) */ targetId?: string; /** Window title (case-insensitive partial match) */ windowTitle?: string; } /** * Find and connect to a running Electron application. * @param options - Optional targeting options to select a specific window * @returns The DevTools target matching the given options * @example * findElectronTarget() // first available main window * findElectronTarget({ targetId: 'ABC123' }) // exact ID match * findElectronTarget({ windowTitle: 'Settings' }) // partial title match */ export declare function findElectronTarget(options?: WindowTargetOptions): Promise; /** * Send an arbitrary CDP method call to an Electron application. * Unlike executeInElectron (which only does Runtime.evaluate), this can invoke * any Chrome DevTools Protocol method (e.g. Input.dispatchMouseEvent). * @param method - CDP method name (e.g. "Input.dispatchMouseEvent") * @param params - Method parameters * @param target - Optional DevTools target to connect to * @returns The raw CDP result object * @example * sendCDPMethod('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 100, y: 200 }) */ export declare function sendCDPMethod(method: string, params: Record, target?: DevToolsTarget): Promise; /** Options forwarded to `CdpConnectionPool.evaluate` from command handlers. */ export interface ExecuteInElectronOptions { /** * When the IIFE returns a Promise, set this to `true` so CDP waits for the * Promise to resolve before responding. Required by all wait/sync commands. */ awaitPromise?: boolean; /** * Hard CDP-level timeout in milliseconds. Use as a safety net above any * in-IIFE `setTimeout` fallback (recommended: userTimeout + ~1000ms). */ timeoutMs?: number; } /** * Per-target serialization queue for `executeInElectron` (#10). * * Why this exists: * CDP's `Runtime.evaluate` does not serialize concurrent in-flight calls * against the same execution context. v2.0.0 had an in-renderer reentrancy * guard (`window._mcpExecuting[codeHash]`) in the eval IIFE, but its * 10-character base64 hash collided for codes sharing a prefix — e.g. * `document.title` and `document.body.children.length` both hashed to * `ZG9jdW1lbn`, raising spurious "Code already executing" failures on * legitimately distinct concurrent calls. * * v2.0.1 removes the in-renderer guard and serializes here instead: a * Promise-chain queue keyed by `targetInfo.id`. Within a single target, * synchronous calls run strictly sequentially. Across different targets they * remain fully parallel. * * `awaitPromise: true` callers BYPASS the queue (see `executeInElectron`). * Wait/observer commands are long-lived by design and must not block actions * that fire the events they are observing. * * Exported for tests only — production code must not touch it. */ export declare const _evaluateQueueByTarget: Map>; /** * Execute JavaScript code in an Electron application via Chrome DevTools Protocol. * @param javascriptCode - Expression to run in the Electron renderer * @param target - Optional DevTools target; defaults to the first discovered window * @param options - Pass `awaitPromise: true` for IIFEs that return a Promise * (used by wait/sync commands). `timeoutMs` enforces a hard CDP-level cap. * @returns Human-readable string formatted by `formatEvaluateResult` */ export declare function executeInElectron(javascriptCode: string, target?: DevToolsTarget, options?: ExecuteInElectronOptions): Promise; /** * Connect to Electron app for real-time log monitoring */ export declare function connectForLogs(target?: DevToolsTarget, onLog?: (log: string) => void): Promise;