@@ -50,10 +50,13 @@ chrome.runtime.onConnect.addListener((port) => {
50
50
} ) ;
51
51
52
52
// background.js recieves message from contentScript.js
53
- chrome . runtime . onMessage . addListener ( ( request ) => {
53
+ chrome . runtime . onMessage . addListener ( ( request , sender ) => {
54
54
const { action } = request ;
55
55
const { persist } = mode ;
56
56
57
+ console . log ( 'request: ' , request )
58
+ console . log ( 'sender: ' , sender )
59
+
57
60
switch ( action ) {
58
61
case 'tabReload' :
59
62
firstSnapshot = true ;
@@ -66,25 +69,31 @@ chrome.runtime.onMessage.addListener((request) => {
66
69
firstSnapshot = false ;
67
70
// don't add anything to snapshot storage if mode is persisting for the initial snapshot
68
71
if ( ! persist ) snapshotArr . push ( request . payload ) ;
69
- bg . postMessage ( {
70
- action : 'initialConnectSnapshots' ,
71
- payload : {
72
- snapshots : snapshotArr ,
73
- mode,
74
- } ,
75
- } ) ;
72
+ if ( bg ) {
73
+ bg . postMessage ( {
74
+ action : 'initialConnectSnapshots' ,
75
+ payload : {
76
+ snapshots : snapshotArr ,
77
+ mode,
78
+ } ,
79
+ } ) ;
80
+ }
76
81
break ;
77
82
}
78
83
snapshotArr . push ( request . payload ) ;
79
84
// TODO:
80
85
// get active tab id
86
+ const tabID = sender . tab . id ;
81
87
// get snapshot arr from tab object
88
+ console . log ( tabID )
82
89
83
90
// send message to devtools
84
- bg . postMessage ( {
85
- action : 'sendSnapshots' ,
86
- payload : snapshotArr ,
87
- } ) ;
91
+ if ( bg ) {
92
+ bg . postMessage ( {
93
+ action : 'sendSnapshots' ,
94
+ payload : snapshotArr ,
95
+ } ) ;
96
+ }
88
97
break ;
89
98
default :
90
99
}
0 commit comments