@@ -2,6 +2,7 @@ import lighthouse from 'lighthouse';
22import chromeLauncher from 'chrome-launcher' ;
33import log from 'lighthouse-logger' ;
44import puppeteer from 'puppeteer' ;
5+ import { install } from '@puppeteer/browsers' ;
56
67export const runLighthouse = async ( url , settings ) => {
78 let chrome ;
@@ -22,19 +23,25 @@ export const runLighthouse = async (url, settings) => {
2223 handleSIGINT : true ,
2324 } ;
2425
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
3127 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+
3239 const browserPath = browser . executablePath ( ) ;
3340 console . log ( `Using Chrome from puppeteer: ${ browserPath } ` ) ;
3441 launchOptions . chromePath = browserPath ;
3542 await browser . close ( ) ;
3643 } catch ( error ) {
37- await browser . close ( ) ;
44+ console . log ( 'Error installing/launching Chrome:' , error . message ) ;
3845 // Fallback to environment variable if puppeteer's Chrome is not available
3946 if ( process . env . CHROME_PATH ) {
4047 console . log ( `Using Chrome from environment: ${ process . env . CHROME_PATH } ` ) ;
0 commit comments