mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-08-30 11:49:50 +02:00
The executeJavaScript path is SUSPENDED by Electron until a page stops loading, so on a page whose trackers never let it settle (Reddit, LinkedIn) every in-page command queues into the 15s backend timeout = the mount-poll wedge that has blocked every agent-loop run. CDP Runtime.evaluate runs in the browser process, out of the renderer's load-blocked event loop, so it does not suspend. This reuses the already-in-production CDP bridge (sendCdp -> send-cdp-command -> wc.debugger.sendCommand, keyed by getWebContentsId, with attach + per-wc serialization + timeout already built) that the AX/click commands use; only the eval path was left on executeJavaScript. No-regression by construction: on any CDP INFRA failure (debugger can't attach because DevTools or a remote-debugging port holds the webContents, or the bridge errors) it falls back to the original executeJavaScript path, and a real page-side exception still surfaces as a throw; window.__OSW_CDP_EVAL__ = false forces the old path. Unwrap logic extracted to cdpEval.ts + 6 unit tests. NOTE not live-demonstrable on a --remote-debugging-port bench: that port globally blocks wc.debugger.attach, so the whole app CDP path (this AND the existing list_interactives) times out there; production and normal dev do not use the port, so attach works and the existing CDP commands prove it
22 lines
903 B
TypeScript
22 lines
903 B
TypeScript
// Turn a CDP `Runtime.evaluate` result into the value, the way webContents.executeJavaScript
|
|
// hands it back: return the serialized value, and throw when the page code itself threw (that
|
|
// arrives as `exceptionDetails`, not as an infra error). Kept pure + separate so it's unit
|
|
// testable without the whole browser-command module and its Electron globals.
|
|
|
|
export interface CdpEvalResult {
|
|
result?: { value?: unknown; type?: string };
|
|
exceptionDetails?: {
|
|
text?: string;
|
|
exception?: { description?: string; value?: unknown };
|
|
};
|
|
}
|
|
|
|
export function unwrapCdpEval(cdp: CdpEvalResult): unknown {
|
|
if (cdp && cdp.exceptionDetails) {
|
|
const ex = cdp.exceptionDetails;
|
|
const msg = (ex.exception && (ex.exception.description || ex.exception.value)) || ex.text || 'eval error in page';
|
|
throw new Error(String(msg));
|
|
}
|
|
return cdp && cdp.result ? cdp.result.value : undefined;
|
|
}
|