forked from yandex/csp-tester
-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
30 lines (24 loc) · 820 Bytes
/
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
'use strict';
var callback = function(details) {
var csp_name = 'Content-Security-Policy';
var csp_value = localStorage['policy'];
details.responseHeaders.map(function(val, i, arr) {
if (val.name == csp_name) {
arr.splice(i, 1);
}
});
if (localStorage['report_only'] == 1) {
csp_name += '-Report-Only';
}
details.responseHeaders.push({name: csp_name, value: csp_value});
return {responseHeaders: details.responseHeaders};
};
var reload = function() {
var urls = {urls:[localStorage['target']]};
chrome.webRequest.onHeadersReceived.removeListener(callback);
if (localStorage['state'] == 1) {
chrome.webRequest.onHeadersReceived.addListener(callback, urls, ["blocking", "responseHeaders"]);
}
return true;
};
reload();