@@ -360,10 +360,13 @@ chrome.runtime.onConnect.addListener(async (port) => {
360360 }
361361
362362 if ( Object . keys ( tabsObj ) . length > 0 ) {
363+ console . log ( 'Sending initial snapshots to devtools:' , tabsObj ) ;
363364 port . postMessage ( {
364365 action : 'initialConnectSnapshots' ,
365366 payload : tabsObj ,
366367 } ) ;
368+ } else {
369+ console . log ( 'No snapshots to send to devtools on reconnect.' ) ;
367370 }
368371
369372 // Handles port disconnection by removing the disconnected port -ellie
@@ -372,17 +375,6 @@ chrome.runtime.onConnect.addListener(async (port) => {
372375 if ( index !== - 1 ) {
373376 console . warn ( `Port at index ${ index } disconnected. Removing it.` ) ;
374377 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- } ) ;
386378 }
387379 } ) ;
388380
@@ -391,10 +383,6 @@ chrome.runtime.onConnect.addListener(async (port) => {
391383 // (i.e. they're all related to the button actions on Reactime)
392384 port . onMessage . addListener ( async ( msg ) => {
393385 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- }
398386
399387 switch ( action ) {
400388 // 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) => {
437425 tabsObj [ tabId ] . mode . paused = payload ;
438426 return true ; // return true so that port remains open
439427
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+ } ) ;
474434 return true ;
475- }
476435
477436 case 'jumpToSnap' :
478437 chrome . tabs . sendMessage ( tabId , msg ) ;
@@ -712,6 +671,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
712671 payload : tabsObj ,
713672 sourceTab,
714673 } ) ;
674+ console . log ( `Sent snapshots to port at index ${ index } ` ) ;
715675 } catch ( error ) {
716676 console . warn ( `Failed to send snapshots to port at index ${ index } :` , error ) ;
717677 }
0 commit comments