-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
57 lines (49 loc) · 1.45 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
window.browser = (function () {
return window.msBrowser || window.browser || window.chrome;
})();
function http_header_analyzer_store_result(name, tab_id, data) {
window.browser.storage.local.get('http_header_analyzer', function(store) {
if ('undefined' == typeof(store) || 'undefined' == typeof(store.http_header_analyzer))
store = {};
else
store = store.http_header_analyzer;
if ('undefined' == typeof(store[tab_id]))
store[tab_id] = {};
store[tab_id][name] = data;
window.browser.storage.local.set({'http_header_analyzer': store}, function(){});
});
}
window.browser.webRequest.onHeadersReceived.addListener(
function(info) {
http_header_analyzer_store_result('responseInfo', info.tabId, info);
},
{
urls: [
'http://*/*',
'https://*/*'
],
types: ['main_frame']
},
['responseHeaders']
);
window.browser.webRequest.onSendHeaders.addListener(
function(info) {
http_header_analyzer_store_result('requestInfo', info.tabId, info);
},
{
urls: [
'http://*/*',
'https://*/*'
],
types: ['main_frame']
},
['requestHeaders']
);
window.browser.tabs.onRemoved.addListener(function(tab_id, removed) {
window.browser.storage.local.get('http_header_analyzer', function(store) {
delete store.http_header_analyzer[tab_id];
});
});
window.browser.windows.onRemoved.addListener(function(windowid) {
window.browser.storage.local.remove('http_header_analyzer');
});