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).
This commit is contained in:
Henrik Skupin 2021-11-11 09:19:23 +01:00 committed by GitHub
parent 790c7a0eb9
commit 51e61696c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -174,6 +174,7 @@ class ChromeLauncher implements ProductLauncher {
pipe: usePipe,
});
let browser;
try {
const connection = await runner.setupConnection({
usePipe,
@ -181,7 +182,7 @@ class ChromeLauncher implements ProductLauncher {
slowMo,
preferredRevision: this._preferredRevision,
});
const browser = await Browser.create(
browser = await Browser.create(
connection,
[],
ignoreHTTPSErrors,
@ -189,13 +190,21 @@ class ChromeLauncher implements ProductLauncher {
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[] {
@ -371,6 +380,7 @@ class FirefoxLauncher implements ProductLauncher {
pipe,
});
let browser;
try {
const connection = await runner.setupConnection({
usePipe: pipe,
@ -378,7 +388,7 @@ class FirefoxLauncher implements ProductLauncher {
slowMo,
preferredRevision: this._preferredRevision,
});
const browser = await Browser.create(
browser = await Browser.create(
connection,
[],
ignoreHTTPSErrors,
@ -386,13 +396,21 @@ class FirefoxLauncher implements ProductLauncher {
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 {