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.
This commit is contained in:
XiaoMan Wang 2026-08-02 20:18:30 +08:00
parent a3259400a3
commit d17a30d0cc
1 changed files with 5 additions and 1 deletions

View File

@ -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<void>((resolve) => {
const timer = setTimeout(resolve, 1000);