1
1
import lighthouse from 'lighthouse' ;
2
2
import chromeLauncher from 'chrome-launcher' ;
3
3
import log from 'lighthouse-logger' ;
4
+ import puppeteer from 'puppeteer' ;
4
5
5
6
export const runLighthouse = async ( url , settings ) => {
6
7
let chrome ;
@@ -21,13 +22,26 @@ export const runLighthouse = async (url, settings) => {
21
22
handleSIGINT : true ,
22
23
} ;
23
24
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
+ }
31
45
}
32
46
33
47
chrome = await chromeLauncher . launch ( launchOptions ) ;
0 commit comments