Skip to content

Commit 0b74cda

Browse files
authored
chore: sort out signal handling (#506)
1 parent f31ef59 commit 0b74cda

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/browserContextFactory.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ class IsolatedContextFactory extends BaseContextFactory {
9898

9999
protected override async _doObtainBrowser(): Promise<playwright.Browser> {
100100
const browserType = playwright[this.browserConfig.browserName];
101-
return browserType.launch(this.browserConfig.launchOptions).catch(error => {
101+
return browserType.launch({
102+
...this.browserConfig.launchOptions,
103+
handleSIGINT: false,
104+
handleSIGTERM: false,
105+
}).catch(error => {
102106
if (error.message.includes('Executable doesn\'t exist'))
103107
throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`);
104108
throw error;
@@ -160,7 +164,12 @@ class PersistentContextFactory implements BrowserContextFactory {
160164
const browserType = playwright[this.browserConfig.browserName];
161165
for (let i = 0; i < 5; i++) {
162166
try {
163-
const browserContext = await browserType.launchPersistentContext(userDataDir, { ...this.browserConfig.launchOptions, ...this.browserConfig.contextOptions });
167+
const browserContext = await browserType.launchPersistentContext(userDataDir, {
168+
...this.browserConfig.launchOptions,
169+
...this.browserConfig.contextOptions,
170+
handleSIGINT: false,
171+
handleSIGTERM: false,
172+
});
164173
const close = () => this._closeBrowserContext(browserContext, userDataDir);
165174
return { browserContext, close };
166175
} catch (error: any) {

src/server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export class Server {
4242
}
4343

4444
setupExitWatchdog() {
45+
let isExiting = false;
4546
const handleExit = async () => {
47+
if (isExiting)
48+
return;
49+
isExiting = true;
4650
setTimeout(() => process.exit(0), 15000);
4751
await Promise.all(this._connectionList.map(connection => connection.close()));
4852
process.exit(0);

0 commit comments

Comments
 (0)