Skip to content

Commit 41df647

Browse files
arturmizpaulirish
authored andcommitted
cli: remove --select-chrome,--skip-autolaunch. Support CHROME_PATH env (#2659)
* --skip-autolaunch flag removed, --select-chrome flag removed * Unused chrome-launcher/ask.ts removed * Added support for CHROME_PATH env variable to replace LIGHTHOUSE_CHROMIUM_PATH * CHROME_PATH env variable documented in CLI help * Added support for CHROME_PATH on macOS
1 parent 5172ff7 commit 41df647

File tree

5 files changed

+45
-60
lines changed

5 files changed

+45
-60
lines changed

chrome-launcher/ask.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

chrome-launcher/chrome-finder.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const fs = require('fs');
99
const path = require('path');
1010
const execSync = require('child_process').execSync;
1111
const execFileSync = require('child_process').execFileSync;
12+
const log = require('lighthouse-logger');
1213

1314
const newLineRegex = /\r?\n/;
1415

@@ -23,6 +24,11 @@ export function darwin() {
2324

2425
const installations: Array<string> = [];
2526

27+
const customChromePath = resolveChromePath();
28+
if (customChromePath) {
29+
installations.push(customChromePath);
30+
}
31+
2632
execSync(
2733
`${LSREGISTER} -dump` +
2834
' | grep -i \'google chrome\\( canary\\)\\?.app$\'' +
@@ -46,25 +52,43 @@ export function darwin() {
4652
{regex: /^\/Applications\/.*Chrome.app/, weight: 100},
4753
{regex: /^\/Applications\/.*Chrome Canary.app/, weight: 101},
4854
{regex: /^\/Volumes\/.*Chrome.app/, weight: -2},
49-
{regex: /^\/Volumes\/.*Chrome Canary.app/, weight: -1}
55+
{regex: /^\/Volumes\/.*Chrome Canary.app/, weight: -1},
56+
{regex: new RegExp(process.env.LIGHTHOUSE_CHROMIUM_PATH), weight: 150},
57+
{regex: new RegExp(process.env.CHROME_PATH), weight: 151}
5058
];
5159
// clang-format on
5260

5361
return sort(installations, priorities);
5462
}
5563

64+
function resolveChromePath() {
65+
if (canAccess(process.env.CHROME_PATH)) {
66+
return process.env.CHROME_PATH as string;
67+
}
68+
69+
if (canAccess(process.env.LIGHTHOUSE_CHROMIUM_PATH)) {
70+
log.warn(
71+
'ChromeLauncher',
72+
'LIGHTHOUSE_CHROMIUM_PATH is deprecated, use CHROME_PATH env variable instead.');
73+
return process.env.LIGHTHOUSE_CHROMIUM_PATH as string;
74+
}
75+
76+
return undefined;
77+
}
78+
5679
/**
5780
* Look for linux executables in 3 ways
58-
* 1. Look into LIGHTHOUSE_CHROMIUM_PATH env variable
81+
* 1. Look into CHROME_PATH env variable
5982
* 2. Look into the directories where .desktop are saved on gnome based distro's
6083
* 3. Look for google-chrome-stable & google-chrome executables by using the which command
6184
*/
6285
export function linux() {
6386
let installations: string[] = [];
6487

65-
// 1. Look into LIGHTHOUSE_CHROMIUM_PATH env variable
66-
if (canAccess(process.env.LIGHTHOUSE_CHROMIUM_PATH)) {
67-
installations.push(process.env.LIGHTHOUSE_CHROMIUM_PATH as string);
88+
// 1. Look into CHROME_PATH env variable
89+
const customChromePath = resolveChromePath();
90+
if (customChromePath) {
91+
installations.push(customChromePath);
6892
}
6993

7094
// 2. Look into the directories where .desktop are saved on gnome based distro's
@@ -96,14 +120,15 @@ export function linux() {
96120

97121
if (!installations.length) {
98122
throw new Error(
99-
'The environment variable LIGHTHOUSE_CHROMIUM_PATH must be set to ' +
123+
'The environment variable CHROME_PATH must be set to ' +
100124
'executable of a build of Chromium version 54.0 or later.');
101125
}
102126

103127
const priorities: Priorities = [
104128
{regex: /chrome-wrapper$/, weight: 51}, {regex: /google-chrome-stable$/, weight: 50},
105129
{regex: /google-chrome$/, weight: 49},
106-
{regex: new RegExp(process.env.LIGHTHOUSE_CHROMIUM_PATH), weight: 100}
130+
{regex: new RegExp(process.env.LIGHTHOUSE_CHROMIUM_PATH), weight: 100},
131+
{regex: new RegExp(process.env.CHROME_PATH), weight: 101}
107132
];
108133

109134
return sort(uniq(installations.filter(Boolean)), priorities);
@@ -117,8 +142,9 @@ export function win32() {
117142
const prefixes =
118143
[process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']];
119144

120-
if (canAccess(process.env.LIGHTHOUSE_CHROMIUM_PATH)) {
121-
installations.push(process.env.LIGHTHOUSE_CHROMIUM_PATH);
145+
const customChromePath = resolveChromePath();
146+
if (customChromePath) {
147+
installations.push(customChromePath);
122148
}
123149

124150
prefixes.forEach(prefix => suffixes.forEach(suffix => {

lighthouse-cli/cli-flags.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const Driver = require('../lighthouse-core/gather/driver.js');
1212
import {GetValidOutputOptions, OutputMode} from './printer';
1313

1414
export interface Flags {
15-
skipAutolaunch: boolean, port: number, selectChrome: boolean, chromeFlags: string, output: any,
16-
outputPath: string, interactive: boolean, saveArtifacts: boolean, saveAssets: boolean,
17-
view: boolean, maxWaitForLoad: number, logLevel: string
15+
port: number, chromeFlags: string, output: any, outputPath: string, interactive: boolean,
16+
saveArtifacts: boolean, saveAssets: boolean, view: boolean, maxWaitForLoad: number,
17+
logLevel: string
1818
}
1919

2020
export function getFlags(manualArgv?: string) {
@@ -71,14 +71,15 @@ export function getFlags(manualArgv?: string) {
7171
'Additional categories to capture with the trace (comma-delimited).',
7272
'config-path': 'The path to the config JSON.',
7373
'chrome-flags':
74-
'Custom flags to pass to Chrome (space-delimited). For a full list of flags, see http://peter.sh/experiments/chromium-command-line-switches/.',
74+
`Custom flags to pass to Chrome (space-delimited). For a full list of flags, see http://peter.sh/experiments/chromium-command-line-switches/.
75+
76+
Environment variables:
77+
CHROME_PATH: Explicit path of intended Chrome binary. If set must point to an executable of a build of Chromium version 54.0 or later. By default, any detected Chrome Canary or Chrome (stable) will be launched.
78+
`,
7579
'perf': 'Use a performance-test-only configuration',
7680
'port': 'The port to use for the debugging protocol. Use 0 for a random port',
7781
'max-wait-for-load':
7882
'The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue. WARNING: Very high values can lead to large traces and instability',
79-
'skip-autolaunch': 'Skip autolaunch of Chrome when already running instance is not found',
80-
'select-chrome':
81-
'Interactively choose version of Chrome to use when multiple installations are found',
8283
'interactive': 'Open Lighthouse in interactive mode'
8384
})
8485

@@ -97,8 +98,7 @@ Example: --output-path=./lighthouse-results.html`,
9798
.boolean([
9899
'disable-storage-reset', 'disable-device-emulation', 'disable-cpu-throttling',
99100
'disable-network-throttling', 'save-assets', 'save-artifacts', 'list-all-audits',
100-
'list-trace-categories', 'perf', 'view', 'skip-autolaunch', 'select-chrome', 'verbose',
101-
'quiet', 'help', 'interactive'
101+
'list-trace-categories', 'perf', 'view', 'verbose', 'quiet', 'help', 'interactive'
102102
])
103103
.choices('output', GetValidOutputOptions())
104104

lighthouse-cli/run.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ interface LighthouseError extends Error {
2929

3030
/**
3131
* Attempts to connect to an instance of Chrome with an open remote-debugging
32-
* port. If none is found and the `skipAutolaunch` flag is not true, launches
33-
* a debuggable instance.
32+
* port. If none is found, launches a debuggable instance.
3433
*/
3534
async function getDebuggableChrome(flags: Flags) {
3635
return await launch(
@@ -39,9 +38,6 @@ async function getDebuggableChrome(flags: Flags) {
3938

4039
function showConnectionError() {
4140
console.error('Unable to connect to Chrome');
42-
console.error(
43-
'If you\'re using lighthouse with --skip-autolaunch, ' +
44-
'make sure you\'re running some other Chrome with a debugger.');
4541
process.exit(_RUNTIME_ERROR_CODE);
4642
}
4743

readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ Options:
7777
--disable-device-emulation Disable Nexus 5X emulation [boolean]
7878
--disable-cpu-throttling Disable CPU throttling [boolean] [default: false]
7979
--disable-network-throttling Disable network throttling [boolean]
80-
--skip-autolaunch Skip autolaunch of Chrome when already running instance is not found [boolean]
81-
--select-chrome Interactively choose version of Chrome to use when multiple installations are found [boolean]
8280
--interactive Open Lighthouse in interactive mode [boolean]
8381

8482
Examples:

0 commit comments

Comments
 (0)