-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
39 lines (34 loc) · 1 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Created by Matrixes, 2021.
*/
let collectedIpAddress = {}
function sendMessageToTabs(tab) {
browser.tabs.sendMessage(
tab,
{collectedIpAddress: collectedIpAddress[tab]},
function (response) {
if (browser.runtime.lastError) {
}
})
if (tab in collectedIpAddress) {
delete collectedIpAddress[tab]
}
}
browser.webRequest.onCompleted.addListener(function (details) {
console.log(details)
if (details.type === "main_frame") {
collectedIpAddress[details.tabId] = details.ip
}
}, {urls: ['<all_urls>'], types: ['main_frame']}, ['responseHeaders'])
browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => {
console.log(tabInfo)
if(changeInfo.status === 'complete') {
sendMessageToTabs(tabId)
}
})
browser.tabs.onRemoved.addListener((tabId, removeInfo) => {
//console.log(tabId, removeInfo)
if (tabId in collectedIpAddress) {
delete collectedIpAddress[tabId]
}
})