Skip to content

Commit 156f3b0

Browse files
committed
look for installation
1 parent 440eb6a commit 156f3b0

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/run-lighthouse.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ import lighthouse from 'lighthouse';
22
import chromeLauncher from 'chrome-launcher';
33
import log from 'lighthouse-logger';
44

5+
// Common Chrome paths in CI environments
6+
const CI_CHROME_PATHS = [
7+
'/usr/bin/google-chrome',
8+
'/usr/bin/google-chrome-stable',
9+
];
10+
511
export const runLighthouse = async (url, settings) => {
612
let chrome;
713
try {
8-
// Set debug level logging to see what's happening
9-
const logLevel = 'info';
14+
const logLevel = settings?.logLevel || 'error';
1015
log.setLevel(logLevel);
1116

1217
console.log('Launching Chrome...');
1318
// Launch Chrome with minimal flags
14-
chrome = await chromeLauncher.launch({
19+
const launchOptions = {
1520
chromeFlags: [
1621
'--headless=new',
1722
'--no-sandbox',
@@ -20,7 +25,29 @@ export const runLighthouse = async (url, settings) => {
2025
],
2126
logLevel,
2227
handleSIGINT: true,
23-
});
28+
};
29+
30+
// In CI, Chrome might be installed in a custom location
31+
if (process.env.CHROME_PATH) {
32+
console.log(`Using Chrome from: ${process.env.CHROME_PATH}`);
33+
launchOptions.chromePath = process.env.CHROME_PATH;
34+
} else {
35+
// Try common CI paths
36+
for (const path of CI_CHROME_PATHS) {
37+
try {
38+
const { execSync } = await import('child_process');
39+
execSync(`test -f ${path}`);
40+
launchOptions.chromePath = path;
41+
console.log(`Found Chrome at: ${path}`);
42+
break;
43+
} catch (e) {
44+
// Path doesn't exist, try next one
45+
continue;
46+
}
47+
}
48+
}
49+
50+
chrome = await chromeLauncher.launch(launchOptions);
2451
console.log('Chrome launched on port:', chrome.port);
2552
console.log('Starting Lighthouse audit for URL:', url);
2653
const results = await lighthouse(

0 commit comments

Comments
 (0)