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
| // useCSP.ts
type Rule = any;
export function useCSP(hostMatch: string[], additionalRules?: Rule[]) {
(async () => {
let currentIndex = 0;
let r = await chrome.declarativeNetRequest.getDynamicRules(),
n = r.map((e) => e.id);
const rules = hostMatch.map((domain, index) => {
currentIndex = index + 1;
return {
id: currentIndex,
priority: 1,
action: {
type: "modifyHeaders",
responseHeaders: [
{ header: "Content-Security-Policy", operation: "remove" },
{
header: "Content-Security-Policy-Report-Only",
operation: "remove",
},
],
},
condition: {
regexFilter: domain,
resourceTypes: ["main_frame", "xmlhttprequest"],
},
} as Rule;
});
console.log(rules);
if (additionalRules && additionalRules.length > 0) {
additionalRules.map((rule) => {
rule.id = ++currentIndex;
rules.push(rule);
});
}
await chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: n,
addRules: rules as any,
});
})();
}
|