-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackground.js
More file actions
50 lines (44 loc) · 1.59 KB
/
background.js
File metadata and controls
50 lines (44 loc) · 1.59 KB
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
const RULE_ID = 1;
// Cross-browser compatibility API
const nativeAPI = typeof browser !== "undefined" ? browser : chrome;
// Helper loop to handle both Promise (Firefox) and Callback (Chrome) behaviors if needed
// However, Chrome MV3 also supports promises for many APIs now.
// We'll stick to a clean async/await pattern where possible or a polyfill approach.
async function updateRules() {
const rule = {
id: RULE_ID,
priority: 1,
action: {
type: "modifyHeaders",
responseHeaders: [
{ header: "X-Frame-Options", operation: "remove" },
{ header: "Content-Security-Policy", operation: "remove" }
]
},
condition: {
urlFilter: "*",
resourceTypes: ["sub_frame"]
}
};
console.log("Nozo: Header stripping rules active for sub_frames.");
// Firefox 'browser' API returns a Promise. Chrome 'chrome' API usually requires a callback
// but in MV3 many methods return a promise if callback is omitted.
try {
if (typeof browser !== "undefined") {
await browser.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [RULE_ID],
addRules: [rule]
});
} else {
await chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [RULE_ID],
addRules: [rule]
});
}
} catch (error) {
console.error("Nozo: Failed to update rules", error);
}
}
nativeAPI.runtime.onInstalled.addListener(() => {
updateRules();
});