11import lighthouse from 'lighthouse' ;
2- import puppeteer from 'puppeteer ' ;
2+ import chromeLauncher from 'chrome-launcher ' ;
33import log from 'lighthouse-logger' ;
44
55export const runLighthouse = async ( url , settings ) => {
6- let browser ;
6+ let chrome ;
77 try {
88 const logLevel = settings ?. logLevel || 'error' ;
99 log . setLevel ( logLevel ) ;
1010
11- // Launch Chrome using Puppeteer with CI-friendly flags
12- browser = await puppeteer . launch ( {
13- headless : 'new' ,
14- args : [
11+ // Launch Chrome using chrome-launcher with additional CI-friendly flags
12+ chrome = await chromeLauncher . launch ( {
13+ chromeFlags : [
14+ '--headless=new' ,
1515 '--no-sandbox' ,
1616 '--disable-gpu' ,
1717 '--disable-dev-shm-usage' ,
@@ -21,18 +21,15 @@ export const runLighthouse = async (url, settings) => {
2121 '--disable-web-security' ,
2222 '--allow-running-insecure-content' ,
2323 '--disable-features=IsolateOrigins,site-per-process' ,
24+ '--single-process' , // Try running in a single process
2425 ] ,
25- ignoreDefaultArgs : [ '--enable-automation' ] ,
26+ handleSIGINT : true ,
27+ chromePath : process . env . CHROME_PATH , // Allow custom Chrome path in CI
2628 } ) ;
27-
28- // Get the browser's websocket endpoint and extract the port
29- const browserWSEndpoint = browser . wsEndpoint ( ) ;
30- const port = parseInt ( browserWSEndpoint . split ( ':' ) [ 2 ] . split ( '/' ) [ 0 ] , 10 ) ;
31-
3229 const results = await lighthouse (
3330 url ,
3431 {
35- port,
32+ port : chrome . port ,
3633 output : 'html' ,
3734 logLevel,
3835 onlyCategories : settings ?. onlyCategories ,
@@ -43,8 +40,8 @@ export const runLighthouse = async (url, settings) => {
4340 ) ;
4441 return results ;
4542 } finally {
46- if ( browser ) {
47- await browser . close ( ) ;
43+ if ( chrome ) {
44+ await chrome . kill ( ) ;
4845 }
4946 }
5047} ;
0 commit comments