-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
99 lines (95 loc) · 3.53 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function sendMessage() {
browser.tabs.query({currentWindow: true, active: true}).then(tabs => {
const url = new URL(tabs[0].url);
browser.storage.local.set({
currentHostname: url.hostname,
currentPathname: url.pathname
});
});
}
// browser.runtime.onMessage.addListener(message => {
// if (message.popupOpen === true) {
// console.log("THE POPUP IS OPEN");
// browser.tabs.query({currentWindow: true, active: true}).then(tabs => {
// const url = new URL(tabs[0].url);
// console.log(url.hostname);
// browser.storage.local.set({
// currentHostname: url.hostname,
// currentPathname: url.pathname
// });
// });
// }
// });
//
//
function logResponse(responseDetails) {
if (responseDetails.documentUrl === undefined) {
let url = new URL(responseDetails.url);
browser.storage.local.get(url.hostname).then(data => {
if (Object.keys(data).length === 0) {
console.log("No data currently avalable");
data[url.hostname] = {
"headers-all":{
},
"headers-security":{
"strict-transport-security": new Set(),
"x-xss-protection": new Set(),
"content-security-policy": new Set(),
"x-frame-options": new Set(),
"x-content-type-options": new Set(),
"cache-control": new Set(),
"server": new Set(),
"x-powered-by": new Set()
},
"linkTags":{
"allURLs": {}
},
"scriptTags":{
"allURLs": {}
}
};
}
data[url.hostname]["headers-all"][url.pathname] = {};
let securityHeaders = [
"strict-transport-security",
"x-xss-protection",
"content-security-policy",
"x-frame-options",
"x-content-type-options",
"cache-control",
"server",
"x-powered-by"
]
for (let header in responseDetails.responseHeaders) {
data[url.hostname]["headers-all"][url.pathname][responseDetails.responseHeaders[header].name] = responseDetails.responseHeaders[header].value;
if (securityHeaders.includes(responseDetails.responseHeaders[header].name.toLowerCase())) {
data[url.hostname]["headers-security"][responseDetails.responseHeaders[header].name.toLowerCase()].add(url.pathname);
}
}
// for (let header in data[url.hostname]["headers-security"]) {
// console.log(responseDetails.responseHeaders);
// if (responseDetails.responseHeaders.includes(header)) {
// data[url.hostname]["headers-security"][header].add(url.pathname);
// }
// }
console.log(data);
browser.storage.local.set(data);
});
};
}
browser.webRequest.onCompleted.addListener(
logResponse,
{urls: ["<all_urls>"]},
["responseHeaders"]
);
browser.runtime.onMessage.addListener(message => {
if (message.popupOpen === true) {
sendMessage();
}
});
let portFromExtension;
function connected(p) {
portFromExtension = p;
portFromExtension.postMessage({greeting: "hi there extension!"});
}
browser.runtime.onConnect.addListener(connected);