From 0b74cdaaf81c8c5d04d2ceca69a4ba147277ff40 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Sun, 1 Jun 2025 14:11:42 -0700 Subject: [PATCH] chore: sort out signal handling (#506) --- src/browserContextFactory.ts | 13 +++++++++++-- src/server.ts | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/browserContextFactory.ts b/src/browserContextFactory.ts index 5c35fc1..723d0a1 100644 --- a/src/browserContextFactory.ts +++ b/src/browserContextFactory.ts @@ -98,7 +98,11 @@ class IsolatedContextFactory extends BaseContextFactory { protected override async _doObtainBrowser(): Promise { const browserType = playwright[this.browserConfig.browserName]; - return browserType.launch(this.browserConfig.launchOptions).catch(error => { + return browserType.launch({ + ...this.browserConfig.launchOptions, + handleSIGINT: false, + handleSIGTERM: false, + }).catch(error => { if (error.message.includes('Executable doesn\'t exist')) throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`); throw error; @@ -160,7 +164,12 @@ class PersistentContextFactory implements BrowserContextFactory { const browserType = playwright[this.browserConfig.browserName]; for (let i = 0; i < 5; i++) { try { - const browserContext = await browserType.launchPersistentContext(userDataDir, { ...this.browserConfig.launchOptions, ...this.browserConfig.contextOptions }); + const browserContext = await browserType.launchPersistentContext(userDataDir, { + ...this.browserConfig.launchOptions, + ...this.browserConfig.contextOptions, + handleSIGINT: false, + handleSIGTERM: false, + }); const close = () => this._closeBrowserContext(browserContext, userDataDir); return { browserContext, close }; } catch (error: any) { diff --git a/src/server.ts b/src/server.ts index b298099..8c143e1 100644 --- a/src/server.ts +++ b/src/server.ts @@ -42,7 +42,11 @@ export class Server { } setupExitWatchdog() { + let isExiting = false; const handleExit = async () => { + if (isExiting) + return; + isExiting = true; setTimeout(() => process.exit(0), 15000); await Promise.all(this._connectionList.map(connection => connection.close())); process.exit(0);