extension: Allow this to work on Firefox when its eventually supported

This commit is contained in:
Daniel Jacobs 2024-06-14 12:12:09 -04:00
parent 10edaf2c48
commit 3a47f8a20f
1 changed files with 25 additions and 10 deletions

View File

@ -15,7 +15,9 @@ async function enable() {
{ {
id: 1, id: 1,
action: { action: {
type: chrome.declarativeNetRequest.RuleActionType.REDIRECT, type:
chrome.declarativeNetRequest.RuleActionType?.REDIRECT ??
"redirect",
redirect: { regexSubstitution: playerPage + "#\\0" }, redirect: { regexSubstitution: playerPage + "#\\0" },
}, },
condition: { condition: {
@ -32,14 +34,17 @@ async function enable() {
}, },
], ],
resourceTypes: [ resourceTypes: [
chrome.declarativeNetRequest.ResourceType.MAIN_FRAME, chrome.declarativeNetRequest.ResourceType?.MAIN_FRAME ??
"main_frame",
], ],
}, },
}, },
{ {
id: 2, id: 2,
action: { action: {
type: chrome.declarativeNetRequest.RuleActionType.REDIRECT, type:
chrome.declarativeNetRequest.RuleActionType?.REDIRECT ??
"redirect",
redirect: { regexSubstitution: playerPage + "#\\0" }, redirect: { regexSubstitution: playerPage + "#\\0" },
}, },
condition: { condition: {
@ -55,29 +60,39 @@ async function enable() {
}, },
], ],
resourceTypes: [ resourceTypes: [
chrome.declarativeNetRequest.ResourceType.MAIN_FRAME, chrome.declarativeNetRequest.ResourceType?.MAIN_FRAME ??
"main_frame",
], ],
}, },
}, },
{ {
id: 3, id: 3,
action: { action: {
type: chrome.declarativeNetRequest.RuleActionType.REDIRECT, type:
chrome.declarativeNetRequest.RuleActionType?.REDIRECT ??
"redirect",
redirect: { regexSubstitution: playerPage + "#\\0" }, redirect: { regexSubstitution: playerPage + "#\\0" },
}, },
condition: { condition: {
regexFilter: "^.*\\.s(?:wf|pl)(\\?.*|#.*|)$", regexFilter: "^.*\\.s(?:wf|pl)(\\?.*|#.*|)$",
excludedResponseHeaders: [{ header: "content-type" }], excludedResponseHeaders: [{ header: "content-type" }],
resourceTypes: [ resourceTypes: [
chrome.declarativeNetRequest.ResourceType.MAIN_FRAME, chrome.declarativeNetRequest.ResourceType?.MAIN_FRAME ??
"main_frame",
], ],
}, },
}, },
]; ];
await utils.declarativeNetRequest.updateDynamicRules({ try {
removeRuleIds: [1, 2, 3], await utils.declarativeNetRequest.updateDynamicRules({
addRules: rules, removeRuleIds: [1, 2, 3],
}); addRules: rules,
});
} catch (e) {
console.info(
"Failed to register rules: responseHeaders condition unsupported",
);
}
} }
if ( if (
!utils.scripting || !utils.scripting ||