Skip to content

Commit

Permalink
extension: Allow this to work on Firefox when its eventually supported
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs committed Jun 14, 2024
1 parent 2190695 commit ce55ea5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion web/packages/extension/manifest_firefox.json5
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"open_in_tab": true,
},
"permissions": [
"<all_urls>", // // To allow script injecting + the internal player to bypass CORS
"<all_urls>", // // To allow script injecting + the internal player to bypass CORS + SWF takeover
"declarativeNetRequest",
"scripting",
"storage"
],
Expand Down
35 changes: 25 additions & 10 deletions web/packages/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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 ||
Expand Down

0 comments on commit ce55ea5

Please sign in to comment.