fix: robustly check for launch executable (#8468)

This commit is contained in:
jrandolf 2022-06-07 15:25:04 +02:00 committed by GitHub
parent 328c3f5b08
commit b54dc55f76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,8 +71,8 @@ class ChromeLauncher implements ProductLauncher {
ignoreDefaultArgs = false, ignoreDefaultArgs = false,
args = [], args = [],
dumpio = false, dumpio = false,
channel = null, channel,
executablePath = null, executablePath,
pipe = false, pipe = false,
env = process.env, env = process.env,
handleSIGINT = true, handleSIGINT = true,
@ -83,7 +83,7 @@ class ChromeLauncher implements ProductLauncher {
slowMo = 0, slowMo = 0,
timeout = 30000, timeout = 30000,
waitForInitialPage = true, waitForInitialPage = true,
debuggingPort = null, debuggingPort,
} = options; } = options;
const chromeArguments = []; const chromeArguments = [];
@ -103,7 +103,7 @@ class ChromeLauncher implements ProductLauncher {
) { ) {
if (pipe) { if (pipe) {
assert( assert(
debuggingPort === null, !debuggingPort,
'Browser should be launched with either pipe or debugging port - not both.' 'Browser should be launched with either pipe or debugging port - not both.'
); );
chromeArguments.push('--remote-debugging-pipe'); chromeArguments.push('--remote-debugging-pipe');
@ -134,23 +134,20 @@ class ChromeLauncher implements ProductLauncher {
isTempUserDataDir = false; isTempUserDataDir = false;
let chromeExecutable = executablePath; let chromeExecutable = executablePath;
if (channel) { if (channel) {
// executablePath is detected by channel, so it should not be specified by user. // executablePath is detected by channel, so it should not be specified by user.
assert( assert(
typeof executablePath === 'string', !chromeExecutable,
'`executablePath` must not be specified when `channel` is given.' '`executablePath` must not be specified when `channel` is given.'
); );
chromeExecutable = executablePathForChannel(channel); chromeExecutable = executablePathForChannel(channel);
} else if (!executablePath) { } else if (!chromeExecutable) {
const { missingText, executablePath } = resolveExecutablePath(this); const { missingText, executablePath } = resolveExecutablePath(this);
if (missingText) throw new Error(missingText); if (missingText) {
chromeExecutable = executablePath; throw new Error(missingText);
} }
chromeExecutable = executablePath;
if (!chromeExecutable) {
throw new Error('chromeExecutable is not found.');
} }
const usePipe = chromeArguments.includes('--remote-debugging-pipe'); const usePipe = chromeArguments.includes('--remote-debugging-pipe');
@ -183,7 +180,7 @@ class ChromeLauncher implements ProductLauncher {
[], [],
ignoreHTTPSErrors, ignoreHTTPSErrors,
defaultViewport, defaultViewport,
runner.proc ?? undefined, runner.proc,
runner.close.bind(runner) runner.close.bind(runner)
); );
} catch (error) { } catch (error) {
@ -262,7 +259,8 @@ class ChromeLauncher implements ProductLauncher {
if (channel) { if (channel) {
return executablePathForChannel(channel); return executablePathForChannel(channel);
} else { } else {
return resolveExecutablePath(this).executablePath; const results = resolveExecutablePath(this);
return results.executablePath;
} }
} }