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.
This commit is contained in:
Nicolas Gomes Ferreira Dos Santos 2026-04-23 21:07:18 -07:00
parent 5d7e494258
commit 7df4295f10
1 changed files with 7 additions and 2 deletions

View File

@ -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 {