@@ -2,16 +2,21 @@ import lighthouse from 'lighthouse';
22import chromeLauncher from 'chrome-launcher' ;
33import 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+
511export 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