11import lighthouse from 'lighthouse' ;
22import chromeLauncher from 'chrome-launcher' ;
33import log from 'lighthouse-logger' ;
4+ import puppeteer from 'puppeteer' ;
45
56export const runLighthouse = async ( url , settings ) => {
67 let chrome ;
@@ -21,13 +22,26 @@ export const runLighthouse = async (url, settings) => {
2122 handleSIGINT : true ,
2223 } ;
2324
24- // Let chrome-launcher find Chrome in the environment
25- if ( process . env . CHROME_PATH ) {
26- console . log ( `Using Chrome from environment: ${ process . env . CHROME_PATH } ` ) ;
27- launchOptions . chromePath = process . env . CHROME_PATH ;
28- } else {
29- // Let chrome-launcher find Chrome automatically
30- console . log ( 'Letting chrome-launcher find Chrome...' ) ;
25+ // Get browser executable from puppeteer
26+ const browser = await puppeteer . launch ( {
27+ headless : 'new' ,
28+ args : [ '--no-sandbox' , '--disable-gpu' , '--disable-dev-shm-usage' ]
29+ } ) ;
30+
31+ try {
32+ const browserPath = browser . executablePath ( ) ;
33+ console . log ( `Using Chrome from puppeteer: ${ browserPath } ` ) ;
34+ launchOptions . chromePath = browserPath ;
35+ await browser . close ( ) ;
36+ } catch ( error ) {
37+ await browser . close ( ) ;
38+ // Fallback to environment variable if puppeteer's Chrome is not available
39+ if ( process . env . CHROME_PATH ) {
40+ console . log ( `Using Chrome from environment: ${ process . env . CHROME_PATH } ` ) ;
41+ launchOptions . chromePath = process . env . CHROME_PATH ;
42+ } else {
43+ console . log ( 'Letting chrome-launcher find Chrome...' ) ;
44+ }
3145 }
3246
3347 chrome = await chromeLauncher . launch ( launchOptions ) ;
0 commit comments