@@ -2,6 +2,7 @@ import lighthouse from 'lighthouse';
2
2
import chromeLauncher from 'chrome-launcher' ;
3
3
import log from 'lighthouse-logger' ;
4
4
import puppeteer from 'puppeteer' ;
5
+ import { install } from '@puppeteer/browsers' ;
5
6
6
7
export const runLighthouse = async ( url , settings ) => {
7
8
let chrome ;
@@ -22,19 +23,25 @@ export const runLighthouse = async (url, settings) => {
22
23
handleSIGINT : true ,
23
24
} ;
24
25
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
-
26
+ // Install Chrome if needed and get its path
31
27
try {
28
+ console . log ( 'Installing Chrome via puppeteer...' ) ;
29
+ await install ( {
30
+ browser : 'chrome' ,
31
+ buildId : 'stable'
32
+ } ) ;
33
+
34
+ const browser = await puppeteer . launch ( {
35
+ headless : 'new' ,
36
+ args : [ '--no-sandbox' , '--disable-gpu' , '--disable-dev-shm-usage' ]
37
+ } ) ;
38
+
32
39
const browserPath = browser . executablePath ( ) ;
33
40
console . log ( `Using Chrome from puppeteer: ${ browserPath } ` ) ;
34
41
launchOptions . chromePath = browserPath ;
35
42
await browser . close ( ) ;
36
43
} catch ( error ) {
37
- await browser . close ( ) ;
44
+ console . log ( 'Error installing/launching Chrome:' , error . message ) ;
38
45
// Fallback to environment variable if puppeteer's Chrome is not available
39
46
if ( process . env . CHROME_PATH ) {
40
47
console . log ( `Using Chrome from environment: ${ process . env . CHROME_PATH } ` ) ;
0 commit comments