From 7df4295f1030f4f34bc4c2edeb60634ee3d57759 Mon Sep 17 00:00:00 2001 From: Nicolas Gomes Ferreira Dos Santos Date: Thu, 23 Apr 2026 21:07:18 -0700 Subject: [PATCH] fix(browse): handle chromeProc spawn error events Adds an error listener on the Chrome child process. Without it, async spawn failures (ENOENT, EACCES, antivirus interference) emit 'error' with no handler and crash the parent process via Node's default behavior. Errors surface via the transport's error path or the stdio null-check guard. Also tightens type casts at the CdpPipeTransport call site to reuse the existing NodeWritable/NodeReadable aliases instead of inline import('node:stream') references. Refs #1136. --- browse/src/cookie-import-browser.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/browse/src/cookie-import-browser.ts b/browse/src/cookie-import-browser.ts index 09def036b..e8d793ea6 100644 --- a/browse/src/cookie-import-browser.ts +++ b/browse/src/cookie-import-browser.ts @@ -880,6 +880,11 @@ export async function importCookiesViaCdp( stdio: ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'], }); + // Without this listener, an async spawn failure (ENOENT, EACCES) would + // emit 'error' and crash the parent process via Node's default handler. + // Errors are surfaced via the transport's error path or the stdio null-check. + chromeProc.on('error', () => {}); + const writeSocket = chromeProc.stdio[3] as NodeJS.WritableStream | null; const readSocket = chromeProc.stdio[4] as NodeJS.ReadableStream | null; if (!writeSocket || !readSocket) { @@ -891,8 +896,8 @@ export async function importCookiesViaCdp( } const transport = new CdpPipeTransport( - writeSocket as unknown as import('node:stream').Writable, - readSocket as unknown as import('node:stream').Readable, + writeSocket as unknown as NodeWritable, + readSocket as unknown as NodeReadable, ); try {