From d17a30d0cc81c938b642e16ebc11141589eab804 Mon Sep 17 00:00:00 2001 From: XiaoMan Wang Date: Sun, 2 Aug 2026 20:18:30 +0800 Subject: [PATCH] fix(browse): guard browser.process() in resolveDisconnectCause .process() only exists on browsers launched by the daemon itself. A browser obtained via connectOverCDP() (or a stub in tests) has no such method, so calling it blind throws inside the disconnect handler and kills the whole daemon with 'browser?.process is not a function'. Guard with a typeof check and fall through to the default (clean) branch when the process handle is unavailable. --- browse/src/browser-manager.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browse/src/browser-manager.ts b/browse/src/browser-manager.ts index f9f3317b5..8ee64e22e 100644 --- a/browse/src/browser-manager.ts +++ b/browse/src/browser-manager.ts @@ -91,7 +91,11 @@ export function shouldEnableChromiumSandbox(): boolean { * restarts on backoff. */ export async function resolveDisconnectCause(browser: Browser | null): Promise<'clean' | 'crash'> { - const proc = browser?.process(); + // `.process()` only exists on browsers we launched ourselves. A browser + // obtained via connectOverCDP() (or a stub in tests) has no such method — + // calling it blind throws inside the disconnect handler, which killed the + // whole daemon with "browser?.process is not a function". + const proc = typeof browser?.process === 'function' ? browser.process() : null; if (proc && proc.exitCode === null && proc.signalCode === null) { await new Promise((resolve) => { const timer = setTimeout(resolve, 1000);