fix(browse): guard browser.process() in resolveDisconnectCause

`.process()` only exists on browsers Playwright launched itself; a browser
from connectOverCDP() (or a test stub) has no such method, so the blind call
threw "browser?.process is not a function" inside the disconnect handler and
took down the daemon. Type-check the method before calling it and treat the
no-method case as no process handle.

Closes #2085.

Contributed by @elan2002 (PR #2434).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-08-14 20:20:57 -07:00
co-authored by Claude Fable 5
parent 0350b2d758
commit 865eaf6f2b
+5 -1
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);