/
headers.js
30 lines (26 loc) · 1.05 KB
/
headers.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
chrome.webRequest.onHeadersReceived.addListener(function(details) {
var headers = details.responseHeaders;
var foundCohort = false;
for(var i = 0, l = headers.length; i < l; ++i) {
if (headers[i].name.toLowerCase() !== 'permissions-policy' || headers[i].value.toLowerCase().indexOf('cohort') === -1) {
continue;
}
const perms = headers[i].value.split(',')
for (var perm in perms) {
if (perm.toLowerCase().indexOf('cohort') === -1) {
headers[i].value += perm + ', ';
continue;
}
foundCohort = true;
headers[i].value += 'interest-cohort=(), ';
}
if (!foundCohort) {
console.warn("Missed header: " + headers[i]);
headers[i].value = 'interest-cohort=()';
}
}
if (!foundCohort) {
headers.push({name: 'Permissions-Policy', value: 'interest-cohort=()' });
}
return {responseHeaders: headers};
}, { urls: [ "<all_urls>" ] }, ['responseHeaders', 'blocking', 'extraHeaders']);