-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
71 lines (65 loc) · 2.17 KB
/
popup.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
function missingSecurityHeaders(headers) {
var securityHeaders = security_headers;
console.log("Headers");
console.log(headers);
var op = headers.map(function(item) {
return item.name.toLowerCase();
});
var missingHeaders = securityHeaders.filter(function(header) {
return op.indexOf(header) < 0;
});
console.log("All headers: ");
console.log(op);
console.log("Missing headers: ");
console.log(missingHeaders);
return missingHeaders;
}
function showHeaders(headers, type) {
p = document.createElement("p");
p.setAttribute("id", type);
ui = document.createElement("ui");
for (var i = 0; i < headers.length; ++i) {
li = document.createElement("li");
header = document.createTextNode(headers[i]);
li.appendChild(header);
ui.appendChild(li);
}
p.appendChild(ui);
return p;
}
function updateView(url, headers) {
document.getElementById('reload-page').hidden = true;
document.getElementById('title').hidden = false;
console.log("Headers for URL");
console.log(headers);
div = document.createElement("div");
origin = document.createTextNode("URL: " + url);
div.appendChild(origin);
missingHeaders = missingSecurityHeaders(headers);
missingHeadersHTML = showHeaders(missingHeaders, 'missing-headers');
div.appendChild(missingHeadersHTML);
div.appendChild(document.createElement("br"));
document.body.appendChild(div);
}
/*
chrome.runtime.onMessage.addListener(presentSecurityWarningsForHeaders);
function presentSecurityWarningsForHeaders(headersForUrl) {
console.log("Updating View");
updateView(headersForUrl);
}*/
chrome.tabs.getSelected(null, function(tab){
currentTabId = tab.id;
chrome.webRequest.onHeadersReceived.addListener(
function(details) {
if(!details.hasOwnProperty("url")) {
return;
}
url = details.url
updateView(details.url, details.responseHeaders);
return {responseHeaders: details.responseHeaders};
},
// filters
{urls: ["<all_urls>"]},
// extraInfoSpec
['responseHeaders', 'extraHeaders']);
});