fix: close the page if an error occurred while automating

Prevent massive memory leak...
This commit is contained in:
2025-04-20 07:23:40 +07:00
parent c6b571c68d
commit bb9a31cc78
2 changed files with 3 additions and 0 deletions

View File

@ -18,6 +18,7 @@ async function spawn(context: BrowserContext, targetUrl: string, changeViewport:
await page.goto(server); await page.goto(server);
} catch (e) { } catch (e) {
logger.error(`[${spawnId}] Error while navigating to proxy website: ${e}`); logger.error(`[${spawnId}] Error while navigating to proxy website: ${e}`);
await page.close();
throw e; throw e;
} }
let targetInput: Locator | null = null; let targetInput: Locator | null = null;
@ -31,6 +32,7 @@ async function spawn(context: BrowserContext, targetUrl: string, changeViewport:
} }
if (!targetInput) { if (!targetInput) {
logger.error(`[${spawnId}] Failed to find input field for URL input`); 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`); throw new Error(`Failed to find input field for URL input`);
} }
await targetInput.fill(targetUrl); await targetInput.fill(targetUrl);

View File

@ -32,6 +32,7 @@ async function keepAlive(page: Page, spawnId: string = "unknown") {
} }
} }
} catch (e) { } catch (e) {
await page.close();
logger.error(`[${spawnId}] Error while keeping the page alive: ${e}`); logger.error(`[${spawnId}] Error while keeping the page alive: ${e}`);
} }
} }