diff --git a/src/node/Launcher.ts b/src/node/Launcher.ts index fad95bdc45fe6..91a1d70f73061 100644 --- a/src/node/Launcher.ts +++ b/src/node/Launcher.ts @@ -71,8 +71,8 @@ class ChromeLauncher implements ProductLauncher { ignoreDefaultArgs = false, args = [], dumpio = false, - channel = null, - executablePath = null, + channel, + executablePath, pipe = false, env = process.env, handleSIGINT = true, @@ -83,7 +83,7 @@ class ChromeLauncher implements ProductLauncher { slowMo = 0, timeout = 30000, waitForInitialPage = true, - debuggingPort = null, + debuggingPort, } = options; const chromeArguments = []; @@ -103,7 +103,7 @@ class ChromeLauncher implements ProductLauncher { ) { if (pipe) { assert( - debuggingPort === null, + !debuggingPort, 'Browser should be launched with either pipe or debugging port - not both.' ); chromeArguments.push('--remote-debugging-pipe'); @@ -133,26 +133,14 @@ class ChromeLauncher implements ProductLauncher { isTempUserDataDir = false; - let chromeExecutable = executablePath; - - if (channel) { - // executablePath is detected by channel, so it should not be specified by user. - assert( - typeof executablePath === 'string', - '`executablePath` must not be specified when `channel` is given.' + if (executablePath && channel) { + throw new Error( + '`executablePath` and `channel` cannot be specified together.' ); - - chromeExecutable = executablePathForChannel(channel); - } else if (!executablePath) { - const { missingText, executablePath } = resolveExecutablePath(this); - if (missingText) throw new Error(missingText); - chromeExecutable = executablePath; - } - - if (!chromeExecutable) { - throw new Error('chromeExecutable is not found.'); } - + const chromeExecutable = !executablePath + ? this.executablePath(channel) + : executablePath; const usePipe = chromeArguments.includes('--remote-debugging-pipe'); const runner = new BrowserRunner( this.product, @@ -183,7 +171,7 @@ class ChromeLauncher implements ProductLauncher { [], ignoreHTTPSErrors, defaultViewport, - runner.proc ?? undefined, + runner.proc, runner.close.bind(runner) ); } catch (error) { @@ -262,7 +250,11 @@ class ChromeLauncher implements ProductLauncher { if (channel) { return executablePathForChannel(channel); } else { - return resolveExecutablePath(this).executablePath; + const results = resolveExecutablePath(this); + if (results.missingText) { + throw new Error(results.missingText); + } + return results.executablePath; } }