Skip to content

Commit

Permalink
cli: remove --select-chrome,--skip-autolaunch. Support CHROME_PATH env (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
arturmiz authored and paulirish committed Jul 11, 2017
1 parent 5172ff7 commit 41df647
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 60 deletions.
35 changes: 0 additions & 35 deletions chrome-launcher/ask.ts

This file was deleted.

44 changes: 35 additions & 9 deletions chrome-launcher/chrome-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;
const execFileSync = require('child_process').execFileSync;
const log = require('lighthouse-logger');

const newLineRegex = /\r?\n/;

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

const installations: Array<string> = [];

const customChromePath = resolveChromePath();
if (customChromePath) {
installations.push(customChromePath);
}

execSync(
`${LSREGISTER} -dump` +
' | grep -i \'google chrome\\( canary\\)\\?.app$\'' +
Expand All @@ -46,25 +52,43 @@ export function darwin() {
{regex: /^\/Applications\/.*Chrome.app/, weight: 100},
{regex: /^\/Applications\/.*Chrome Canary.app/, weight: 101},
{regex: /^\/Volumes\/.*Chrome.app/, weight: -2},
{regex: /^\/Volumes\/.*Chrome Canary.app/, weight: -1}
{regex: /^\/Volumes\/.*Chrome Canary.app/, weight: -1},
{regex: new RegExp(process.env.LIGHTHOUSE_CHROMIUM_PATH), weight: 150},
{regex: new RegExp(process.env.CHROME_PATH), weight: 151}
];
// clang-format on

return sort(installations, priorities);
}

function resolveChromePath() {
if (canAccess(process.env.CHROME_PATH)) {
return process.env.CHROME_PATH as string;
}

if (canAccess(process.env.LIGHTHOUSE_CHROMIUM_PATH)) {
log.warn(
'ChromeLauncher',
'LIGHTHOUSE_CHROMIUM_PATH is deprecated, use CHROME_PATH env variable instead.');
return process.env.LIGHTHOUSE_CHROMIUM_PATH as string;
}

return undefined;
}

/**
* Look for linux executables in 3 ways
* 1. Look into LIGHTHOUSE_CHROMIUM_PATH env variable
* 1. Look into CHROME_PATH env variable
* 2. Look into the directories where .desktop are saved on gnome based distro's
* 3. Look for google-chrome-stable & google-chrome executables by using the which command
*/
export function linux() {
let installations: string[] = [];

// 1. Look into LIGHTHOUSE_CHROMIUM_PATH env variable
if (canAccess(process.env.LIGHTHOUSE_CHROMIUM_PATH)) {
installations.push(process.env.LIGHTHOUSE_CHROMIUM_PATH as string);
// 1. Look into CHROME_PATH env variable
const customChromePath = resolveChromePath();
if (customChromePath) {
installations.push(customChromePath);
}

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

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

const priorities: Priorities = [
{regex: /chrome-wrapper$/, weight: 51}, {regex: /google-chrome-stable$/, weight: 50},
{regex: /google-chrome$/, weight: 49},
{regex: new RegExp(process.env.LIGHTHOUSE_CHROMIUM_PATH), weight: 100}
{regex: new RegExp(process.env.LIGHTHOUSE_CHROMIUM_PATH), weight: 100},
{regex: new RegExp(process.env.CHROME_PATH), weight: 101}
];

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

if (canAccess(process.env.LIGHTHOUSE_CHROMIUM_PATH)) {
installations.push(process.env.LIGHTHOUSE_CHROMIUM_PATH);
const customChromePath = resolveChromePath();
if (customChromePath) {
installations.push(customChromePath);
}

prefixes.forEach(prefix => suffixes.forEach(suffix => {
Expand Down
18 changes: 9 additions & 9 deletions lighthouse-cli/cli-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const Driver = require('../lighthouse-core/gather/driver.js');
import {GetValidOutputOptions, OutputMode} from './printer';

export interface Flags {
skipAutolaunch: boolean, port: number, selectChrome: boolean, chromeFlags: string, output: any,
outputPath: string, interactive: boolean, saveArtifacts: boolean, saveAssets: boolean,
view: boolean, maxWaitForLoad: number, logLevel: string
port: number, chromeFlags: string, output: any, outputPath: string, interactive: boolean,
saveArtifacts: boolean, saveAssets: boolean, view: boolean, maxWaitForLoad: number,
logLevel: string
}

export function getFlags(manualArgv?: string) {
Expand Down Expand Up @@ -71,14 +71,15 @@ export function getFlags(manualArgv?: string) {
'Additional categories to capture with the trace (comma-delimited).',
'config-path': 'The path to the config JSON.',
'chrome-flags':
'Custom flags to pass to Chrome (space-delimited). For a full list of flags, see http://peter.sh/experiments/chromium-command-line-switches/.',
`Custom flags to pass to Chrome (space-delimited). For a full list of flags, see http://peter.sh/experiments/chromium-command-line-switches/.
Environment variables:
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.
`,
'perf': 'Use a performance-test-only configuration',
'port': 'The port to use for the debugging protocol. Use 0 for a random port',
'max-wait-for-load':
'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',
'skip-autolaunch': 'Skip autolaunch of Chrome when already running instance is not found',
'select-chrome':
'Interactively choose version of Chrome to use when multiple installations are found',
'interactive': 'Open Lighthouse in interactive mode'
})

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

Expand Down
6 changes: 1 addition & 5 deletions lighthouse-cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ interface LighthouseError extends Error {

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

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

Expand Down
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ Options:
--disable-device-emulation Disable Nexus 5X emulation [boolean]
--disable-cpu-throttling Disable CPU throttling [boolean] [default: false]
--disable-network-throttling Disable network throttling [boolean]
--skip-autolaunch Skip autolaunch of Chrome when already running instance is not found [boolean]
--select-chrome Interactively choose version of Chrome to use when multiple installations are found [boolean]
--interactive Open Lighthouse in interactive mode [boolean]

Examples:
Expand Down

0 comments on commit 41df647

Please sign in to comment.