@@ -340,14 +340,14 @@ function performAttach() {
340
340
341
341
chrome . debugger . sendCommand (
342
342
{ tabId : currentTabId } ,
343
- "Console .enable" ,
343
+ "Runtime .enable" ,
344
344
{ } ,
345
345
( ) => {
346
346
if ( chrome . runtime . lastError ) {
347
- console . error ( "Failed to enable console :" , chrome . runtime . lastError ) ;
347
+ console . error ( "Failed to enable runtime :" , chrome . runtime . lastError ) ;
348
348
return ;
349
349
}
350
- console . log ( "Console API successfully enabled" ) ;
350
+ console . log ( "Runtime API successfully enabled" ) ;
351
351
}
352
352
) ;
353
353
} ) ;
@@ -390,12 +390,57 @@ const consoleMessageListener = (source, method, params) => {
390
390
return ;
391
391
}
392
392
393
- if ( method === "Console.messageAdded" ) {
394
- console . log ( "Console message received:" , params . message ) ;
393
+ if ( method === "Runtime.exceptionThrown" ) {
395
394
const entry = {
396
- type : params . message . level === "error" ? "console-error" : "console-log" ,
397
- level : params . message . level ,
398
- message : params . message . text ,
395
+ type : "console-error" ,
396
+ message :
397
+ params . exceptionDetails . exception ?. description ||
398
+ JSON . stringify ( params . exceptionDetails ) ,
399
+ level : "error" ,
400
+ timestamp : Date . now ( ) ,
401
+ } ;
402
+ console . log ( "Sending runtime exception:" , entry ) ;
403
+ sendToBrowserConnector ( entry ) ;
404
+ }
405
+
406
+ if ( method === "Runtime.consoleAPICalled" ) {
407
+ // Process all arguments from the console call
408
+ let formattedMessage = "" ;
409
+ const args = params . args || [ ] ;
410
+
411
+ // Extract all arguments and combine them
412
+ if ( args . length > 0 ) {
413
+ // Try to build a meaningful representation of all arguments
414
+ try {
415
+ formattedMessage = args
416
+ . map ( ( arg ) => {
417
+ // Handle different types of arguments
418
+ if ( arg . type === "string" ) {
419
+ return arg . value ;
420
+ } else if ( arg . type === "object" && arg . preview ) {
421
+ // For objects, include their preview or description
422
+ return JSON . stringify ( arg . preview ) ;
423
+ } else if ( arg . description ) {
424
+ // Some objects have descriptions
425
+ return arg . description ;
426
+ } else {
427
+ // Fallback for other types
428
+ return arg . value || arg . description || JSON . stringify ( arg ) ;
429
+ }
430
+ } )
431
+ . join ( " " ) ;
432
+ } catch ( e ) {
433
+ // Fallback if processing fails
434
+ console . error ( "Failed to process console arguments:" , e ) ;
435
+ formattedMessage =
436
+ args [ 0 ] ?. value || "Unable to process console arguments" ;
437
+ }
438
+ }
439
+
440
+ const entry = {
441
+ type : params . type === "error" ? "console-error" : "console-log" ,
442
+ level : params . type ,
443
+ message : formattedMessage ,
399
444
timestamp : Date . now ( ) ,
400
445
} ;
401
446
console . log ( "Sending console entry:" , entry ) ;
0 commit comments