@@ -360,10 +360,13 @@ chrome.runtime.onConnect.addListener(async (port) => {
360
360
}
361
361
362
362
if ( Object . keys ( tabsObj ) . length > 0 ) {
363
+ console . log ( 'Sending initial snapshots to devtools:' , tabsObj ) ;
363
364
port . postMessage ( {
364
365
action : 'initialConnectSnapshots' ,
365
366
payload : tabsObj ,
366
367
} ) ;
368
+ } else {
369
+ console . log ( 'No snapshots to send to devtools on reconnect.' ) ;
367
370
}
368
371
369
372
// Handles port disconnection by removing the disconnected port -ellie
@@ -372,17 +375,6 @@ chrome.runtime.onConnect.addListener(async (port) => {
372
375
if ( index !== - 1 ) {
373
376
console . warn ( `Port at index ${ index } disconnected. Removing it.` ) ;
374
377
portsArr . splice ( index , 1 ) ;
375
-
376
- // Notify remaining ports about the disconnection
377
- portsArr . forEach ( ( remainingPort ) => {
378
- try {
379
- remainingPort . postMessage ( {
380
- action : 'portDisconnect' ,
381
- } ) ;
382
- } catch ( error ) {
383
- console . warn ( 'Failed to notify port of disconnection:' , error ) ;
384
- }
385
- } ) ;
386
378
}
387
379
} ) ;
388
380
@@ -391,10 +383,6 @@ chrome.runtime.onConnect.addListener(async (port) => {
391
383
// (i.e. they're all related to the button actions on Reactime)
392
384
port . onMessage . addListener ( async ( msg ) => {
393
385
const { action, payload, tabId } = msg ;
394
- console . log ( `Received message - Action: ${ action } , Payload:` , payload ) ;
395
- if ( ! payload && [ 'import' , 'setPause' , 'jumpToSnap' ] . includes ( action ) ) {
396
- console . error ( `Invalid payload received for action: ${ action } ` , new Error ( ) . stack ) ;
397
- }
398
386
399
387
switch ( action ) {
400
388
// import action comes through when the user uses the "upload" button on the front end to import an existing snapshot tree
@@ -437,42 +425,13 @@ chrome.runtime.onConnect.addListener(async (port) => {
437
425
tabsObj [ tabId ] . mode . paused = payload ;
438
426
return true ; // return true so that port remains open
439
427
440
- // Handling the launchContentScript case with proper validation
441
- case 'launchContentScript' : {
442
- if ( ! tabId ) {
443
- console . error ( 'No tabId provided for content script injection' ) ;
444
- return false ;
445
- }
446
-
447
- try {
448
- // Validate the tab exists before injecting
449
- chrome . tabs . get ( tabId , async ( tab ) => {
450
- if ( chrome . runtime . lastError ) {
451
- console . error ( 'Error getting tab:' , chrome . runtime . lastError ) ;
452
- return ;
453
- }
454
-
455
- // Skip injection for chrome:// URLs
456
- if ( tab . url ?. startsWith ( 'chrome://' ) ) {
457
- console . warn ( 'Cannot inject scripts into chrome:// URLs' ) ;
458
- return ;
459
- }
460
-
461
- try {
462
- await chrome . scripting . executeScript ( {
463
- target : { tabId : tab . id } ,
464
- files : [ 'bundles/content.bundle.js' ] ,
465
- } ) ;
466
- console . log ( 'Content script injected successfully' ) ;
467
- } catch ( err ) {
468
- console . error ( 'Error injecting content script:' , err ) ;
469
- }
470
- } ) ;
471
- } catch ( err ) {
472
- console . error ( 'Error in launchContentScript:' , err ) ;
473
- }
428
+ case 'launchContentScript' :
429
+ //if (tab.url?.startsWith("chrome://")) return undefined;
430
+ chrome . scripting . executeScript ( {
431
+ target : { tabId } ,
432
+ files : [ 'bundles/content.bundle.js' ] ,
433
+ } ) ;
474
434
return true ;
475
- }
476
435
477
436
case 'jumpToSnap' :
478
437
chrome . tabs . sendMessage ( tabId , msg ) ;
@@ -712,6 +671,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
712
671
payload : tabsObj ,
713
672
sourceTab,
714
673
} ) ;
674
+ console . log ( `Sent snapshots to port at index ${ index } ` ) ;
715
675
} catch ( error ) {
716
676
console . warn ( `Failed to send snapshots to port at index ${ index } :` , error ) ;
717
677
}
0 commit comments