diff --git a/web/packages/extension/manifest_firefox.json5 b/web/packages/extension/manifest_firefox.json5 index e5949f8d0ffe4..97980ed946bc8 100644 --- a/web/packages/extension/manifest_firefox.json5 +++ b/web/packages/extension/manifest_firefox.json5 @@ -48,7 +48,8 @@ "open_in_tab": true, }, "permissions": [ - "", // // To allow script injecting + the internal player to bypass CORS + "", // // To allow script injecting + the internal player to bypass CORS + SWF takeover + "declarativeNetRequest", "scripting", "storage" ], diff --git a/web/packages/extension/src/background.ts b/web/packages/extension/src/background.ts index 9e99c8a80db68..b224b1cbf7c8b 100644 --- a/web/packages/extension/src/background.ts +++ b/web/packages/extension/src/background.ts @@ -15,7 +15,9 @@ async function enable() { { id: 1, action: { - type: chrome.declarativeNetRequest.RuleActionType.REDIRECT, + type: + chrome.declarativeNetRequest.RuleActionType?.REDIRECT ?? + "redirect", redirect: { regexSubstitution: playerPage + "#\\0" }, }, condition: { @@ -32,14 +34,17 @@ async function enable() { }, ], resourceTypes: [ - chrome.declarativeNetRequest.ResourceType.MAIN_FRAME, + chrome.declarativeNetRequest.ResourceType?.MAIN_FRAME ?? + "main_frame", ], }, }, { id: 2, action: { - type: chrome.declarativeNetRequest.RuleActionType.REDIRECT, + type: + chrome.declarativeNetRequest.RuleActionType?.REDIRECT ?? + "redirect", redirect: { regexSubstitution: playerPage + "#\\0" }, }, condition: { @@ -54,29 +59,39 @@ async function enable() { }, ], resourceTypes: [ - chrome.declarativeNetRequest.ResourceType.MAIN_FRAME, + chrome.declarativeNetRequest.ResourceType?.MAIN_FRAME ?? + "main_frame", ], }, }, { id: 3, action: { - type: chrome.declarativeNetRequest.RuleActionType.REDIRECT, + type: + chrome.declarativeNetRequest.RuleActionType?.REDIRECT ?? + "redirect", redirect: { regexSubstitution: playerPage + "#\\0" }, }, condition: { regexFilter: "^.*\\.s(?:wf|pl)(\\?.*|#.*|)$", excludedResponseHeaders: [{ header: "content-type" }], resourceTypes: [ - chrome.declarativeNetRequest.ResourceType.MAIN_FRAME, + chrome.declarativeNetRequest.ResourceType?.MAIN_FRAME ?? + "main_frame", ], }, }, ]; - await utils.declarativeNetRequest.updateDynamicRules({ - removeRuleIds: [1, 2, 3], - addRules: rules, - }); + try { + await utils.declarativeNetRequest.updateDynamicRules({ + removeRuleIds: [1, 2, 3], + addRules: rules, + }); + } catch (e) { + console.info( + "Failed to register rules: responseHeaders condition unsupported", + ); + } } if ( !utils.scripting ||