@@ -233,14 +233,43 @@ async function runLighthouse(url) {
233
233
] ,
234
234
} ) ;
235
235
236
- const result = await lighthouse ( url , {
237
- port : 9222 ,
238
- output : "html" ,
239
- logLevel : "error" ,
240
- } ) ;
236
+ // Capture console output to filter Lighthouse internal errors
237
+ const originalConsoleError = console . error ;
238
+ const lighthouseErrors = [ ] ;
239
+
240
+ console . error = ( ...args ) => {
241
+ const message = args . join ( " " ) ;
242
+ if (
243
+ message . includes ( "LanternError" ) ||
244
+ message . includes ( "Invalid dependency graph" )
245
+ ) {
246
+ lighthouseErrors . push ( message ) ;
247
+ // Show a cleaner warning instead of the full stack trace
248
+ if ( lighthouseErrors . length === 1 ) {
249
+ console . warn (
250
+ chalk . yellow (
251
+ " └─ ⚠️ Lighthouse internal warning (analysis will continue)"
252
+ )
253
+ ) ;
254
+ }
255
+ } else {
256
+ originalConsoleError ( ...args ) ;
257
+ }
258
+ } ;
259
+
260
+ try {
261
+ const result = await lighthouse ( url , {
262
+ port : 9222 ,
263
+ output : "html" ,
264
+ logLevel : "error" ,
265
+ } ) ;
241
266
242
- await browser . close ( ) ;
243
- return result ;
267
+ return result ;
268
+ } finally {
269
+ // Restore original console.error
270
+ console . error = originalConsoleError ;
271
+ await browser . close ( ) ;
272
+ }
244
273
}
245
274
246
275
( async ( ) => {
@@ -291,7 +320,7 @@ async function runLighthouse(url) {
291
320
if ( actualScore < options . threshold ) {
292
321
console . warn (
293
322
chalk . red (
294
- `⚠️ Score ${ actualScore } is below threshold of ${ options . threshold } `
323
+ `⚠️ Score ${ actualScore } is below threshold of ${ options . threshold } `
295
324
)
296
325
) ;
297
326
process . exitCode = 1 ; // does not exit immediately, just sets failure
@@ -317,7 +346,7 @@ async function runLighthouse(url) {
317
346
318
347
if ( urls . length > accessibleUrls . length ) {
319
348
console . log (
320
- `${ chalk . yellow ( "⚠️ Skipped (inaccessible):" ) } ${
349
+ `${ chalk . yellow ( "⚠️ Skipped (inaccessible):" ) } ${
321
350
urls . length - accessibleUrls . length
322
351
} `
323
352
) ;
0 commit comments