Skip to content

Commit c017597

Browse files
committed
tab id
1 parent 69eb3e6 commit c017597

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/extension/background.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ chrome.runtime.onConnect.addListener((port) => {
5050
});
5151

5252
// background.js recieves message from contentScript.js
53-
chrome.runtime.onMessage.addListener((request) => {
53+
chrome.runtime.onMessage.addListener((request, sender) => {
5454
const { action } = request;
5555
const { persist } = mode;
5656

57+
console.log('request: ', request)
58+
console.log('sender: ', sender)
59+
5760
switch (action) {
5861
case 'tabReload':
5962
firstSnapshot = true;
@@ -66,25 +69,31 @@ chrome.runtime.onMessage.addListener((request) => {
6669
firstSnapshot = false;
6770
// don't add anything to snapshot storage if mode is persisting for the initial snapshot
6871
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+
}
7681
break;
7782
}
7883
snapshotArr.push(request.payload);
7984
// TODO:
8085
// get active tab id
86+
const tabID = sender.tab.id;
8187
// get snapshot arr from tab object
88+
console.log(tabID)
8289

8390
// 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+
}
8897
break;
8998
default:
9099
}

0 commit comments

Comments
 (0)