fix: close the page if an error occurred while automating
Prevent massive memory leak...
This commit is contained in:
@ -18,6 +18,7 @@ async function spawn(context: BrowserContext, targetUrl: string, changeViewport:
|
||||
await page.goto(server);
|
||||
} catch (e) {
|
||||
logger.error(`[${spawnId}] Error while navigating to proxy website: ${e}`);
|
||||
await page.close();
|
||||
throw e;
|
||||
}
|
||||
let targetInput: Locator | null = null;
|
||||
@ -31,6 +32,7 @@ async function spawn(context: BrowserContext, targetUrl: string, changeViewport:
|
||||
}
|
||||
if (!targetInput) {
|
||||
logger.error(`[${spawnId}] Failed to find input field for URL input`);
|
||||
await page.close();
|
||||
throw new Error(`Failed to find input field for URL input`);
|
||||
}
|
||||
await targetInput.fill(targetUrl);
|
||||
|
||||
@ -32,6 +32,7 @@ async function keepAlive(page: Page, spawnId: string = "unknown") {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
await page.close();
|
||||
logger.error(`[${spawnId}] Error while keeping the page alive: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user