Skip to content

Commit 51e6169

Browse files
authored
fix: only kill the process when there is no browser instance available (#7762)
When the browser has been started and we have a valid reference lets make use of it instead of force-killing the process. A force kill should probably be the last resort in cleaning up the process. This will help with Firefox as described on #7668 (comment).
1 parent 790c7a0 commit 51e6169

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/node/Launcher.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,28 +174,37 @@ class ChromeLauncher implements ProductLauncher {
174174
pipe: usePipe,
175175
});
176176

177+
let browser;
177178
try {
178179
const connection = await runner.setupConnection({
179180
usePipe,
180181
timeout,
181182
slowMo,
182183
preferredRevision: this._preferredRevision,
183184
});
184-
const browser = await Browser.create(
185+
browser = await Browser.create(
185186
connection,
186187
[],
187188
ignoreHTTPSErrors,
188189
defaultViewport,
189190
runner.proc,
190191
runner.close.bind(runner)
191192
);
192-
if (waitForInitialPage)
193-
await browser.waitForTarget((t) => t.type() === 'page', { timeout });
194-
return browser;
195193
} catch (error) {
196194
runner.kill();
197195
throw error;
198196
}
197+
198+
if (waitForInitialPage) {
199+
try {
200+
await browser.waitForTarget((t) => t.type() === 'page', { timeout });
201+
} catch (error) {
202+
await browser.close();
203+
throw error;
204+
}
205+
}
206+
207+
return browser;
199208
}
200209

201210
defaultArgs(options: BrowserLaunchArgumentOptions = {}): string[] {
@@ -371,28 +380,37 @@ class FirefoxLauncher implements ProductLauncher {
371380
pipe,
372381
});
373382

383+
let browser;
374384
try {
375385
const connection = await runner.setupConnection({
376386
usePipe: pipe,
377387
timeout,
378388
slowMo,
379389
preferredRevision: this._preferredRevision,
380390
});
381-
const browser = await Browser.create(
391+
browser = await Browser.create(
382392
connection,
383393
[],
384394
ignoreHTTPSErrors,
385395
defaultViewport,
386396
runner.proc,
387397
runner.close.bind(runner)
388398
);
389-
if (waitForInitialPage)
390-
await browser.waitForTarget((t) => t.type() === 'page', { timeout });
391-
return browser;
392399
} catch (error) {
393400
runner.kill();
394401
throw error;
395402
}
403+
404+
if (waitForInitialPage) {
405+
try {
406+
await browser.waitForTarget((t) => t.type() === 'page', { timeout });
407+
} catch (error) {
408+
await browser.close();
409+
throw error;
410+
}
411+
}
412+
413+
return browser;
396414
}
397415

398416
executablePath(): string {

0 commit comments

Comments
 (0)