feat: Enhance runExecution function with proactive browser health checks to prevent zombie instances

This commit is contained in:
Nawaz Dhandala
2026-02-27 14:02:50 +00:00
parent ac7fea3a4b
commit 8fbc003a30

View File

@@ -452,6 +452,14 @@ async function runExecution(config: WorkerConfig): Promise<WorkerResult> {
context = null;
}
// In --single-process mode, closing a context can destabilize the browser.
// Proactively check health so the next execution doesn't waste time on a zombie.
if (currentBrowser && !currentBrowser.isConnected()) {
currentBrowser = null;
currentBrowserType = null;
currentProxyServer = null;
}
// Convert screenshots from Buffer to base64
if (returnObj["screenshots"]) {
const screenshots: Record<string, unknown> = returnObj[
@@ -485,6 +493,13 @@ async function runExecution(config: WorkerConfig): Promise<WorkerResult> {
// ignore cleanup errors
}
}
// Proactively detect zombie browser after context cleanup
if (currentBrowser && !currentBrowser.isConnected()) {
currentBrowser = null;
currentBrowserType = null;
currentProxyServer = null;
}
}
return workerResult;