Skip to content

Commit

Permalink
fix: only kill the process when there is no browser instance available (
Browse files Browse the repository at this point in the history
#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).
  • Loading branch information
whimboo committed Nov 11, 2021
1 parent 790c7a0 commit 51e6169
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/node/Launcher.ts
Expand Up @@ -174,28 +174,37 @@ class ChromeLauncher implements ProductLauncher {
pipe: usePipe,
});

let browser;
try {
const connection = await runner.setupConnection({
usePipe,
timeout,
slowMo,
preferredRevision: this._preferredRevision,
});
const browser = await Browser.create(
browser = await Browser.create(
connection,
[],
ignoreHTTPSErrors,
defaultViewport,
runner.proc,
runner.close.bind(runner)
);
if (waitForInitialPage)
await browser.waitForTarget((t) => t.type() === 'page', { timeout });
return browser;
} catch (error) {
runner.kill();
throw error;
}

if (waitForInitialPage) {
try {
await browser.waitForTarget((t) => t.type() === 'page', { timeout });
} catch (error) {
await browser.close();
throw error;
}
}

return browser;
}

defaultArgs(options: BrowserLaunchArgumentOptions = {}): string[] {
Expand Down Expand Up @@ -371,28 +380,37 @@ class FirefoxLauncher implements ProductLauncher {
pipe,
});

let browser;
try {
const connection = await runner.setupConnection({
usePipe: pipe,
timeout,
slowMo,
preferredRevision: this._preferredRevision,
});
const browser = await Browser.create(
browser = await Browser.create(
connection,
[],
ignoreHTTPSErrors,
defaultViewport,
runner.proc,
runner.close.bind(runner)
);
if (waitForInitialPage)
await browser.waitForTarget((t) => t.type() === 'page', { timeout });
return browser;
} catch (error) {
runner.kill();
throw error;
}

if (waitForInitialPage) {
try {
await browser.waitForTarget((t) => t.type() === 'page', { timeout });
} catch (error) {
await browser.close();
throw error;
}
}

return browser;
}

executablePath(): string {
Expand Down

0 comments on commit 51e6169

Please sign in to comment.