Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search in Path for chrome.exe #218

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use which -a on Linux and where on Windows to find more binaries
magneticflux- committed Mar 15, 2022
commit 0324b89fa921ca66c441ab43137c959378bae5b1
42 changes: 25 additions & 17 deletions src/chrome-finder.ts
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@

import fs = require('fs');
import path = require('path');
import {homedir} from 'os';
import {execSync, execFileSync} from 'child_process';
import escapeRegExp = require('escape-string-regexp');
const log = require('lighthouse-logger');
import {homedir} from 'os';
import {execFileSync, execSync} from 'child_process';
import {ChromePathNotSetError, getWSLLocalAppDataPath, toWSLPath} from './utils';

import {getWSLLocalAppDataPath, toWSLPath, ChromePathNotSetError} from './utils';
const log = require('lighthouse-logger');

const newLineRegex = /\r?\n/;

@@ -136,18 +136,15 @@ export function linux() {
'chromium-browser',
'chromium',
];
executables.forEach((executable: string) => {
try {
const chromePath =
execFileSync('which', [executable], {stdio: 'pipe'}).toString().split(newLineRegex)[0];

if (canAccess(chromePath)) {
installations.push(chromePath);
}
} catch (e) {
// Not installed.
}
});
try {
execFileSync('which', ['-a', ...executables], {stdio: 'pipe'})
.toString()
.split(newLineRegex)
.filter(canAccess)
.forEach((chromePath: string) => installations.push(chromePath));
} catch (e) {
// Not installed.
}

if (!installations.length) {
throw new ChromePathNotSetError();
@@ -191,7 +188,8 @@ export function win32() {
`${path.sep}chrome.exe`
];
const prefixes = [
process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)'], ...process.env.PATH?.split(path.delimiter) ?? []
process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)'],
...process.env.PATH?.split(path.delimiter) ?? []
].filter(Boolean) as string[];

const customChromePath = resolveChromePath();
@@ -207,6 +205,16 @@ export function win32() {
}
}));

try {
execFileSync('where.exe', ['chrome.exe'], {stdio: 'pipe'})
.toString()
.split(newLineRegex)
.filter((path: string) => !path.startsWith('INFO: ') && canAccess(path))
.forEach((chromePath: string) => installations.push(chromePath));
} catch (e) {
// Not installed.
}

return installations;
}