Skip to content

Commit

Permalink
extension: Fix 4399 CORS and Flash detection issue (close #13943) (#1…
Browse files Browse the repository at this point in the history
…6750)

Co-authored-by: Zhentao Lu <[email protected]>
  • Loading branch information
riku-42 and Zhentao Lu authored Jun 21, 2024
1 parent dc03f54 commit 036839f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions web/packages/extension/4399_rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"id": 1,
"priority": 1,
"condition": {
"initiatorDomains": ["4399.com"],
"urlFilter": "|*.swf",
"resourceTypes": ["xmlhttprequest"]
},
"action": {
"type": "modifyHeaders",
"responseHeaders": [
{
"header": "Access-Control-Allow-Origin",
"operation": "set",
"value": "https://www.4399.com"
}
]
}
}
]
14 changes: 14 additions & 0 deletions web/packages/extension/manifest_other.json5
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"js": ["dist/content.js"],
"all_frames": true,
"run_at": "document_start",
},
{
"matches": ["https://www.4399.com/flash/*"],
"js": ["dist/siteContentScript4399.js"],
"world": "MAIN",
"run_at": "document_start",
}
],

Expand All @@ -50,11 +56,19 @@
"permissions": [
"storage",
"scripting",
"declarativeNetRequest",
],
"web_accessible_resources": [{
"resources": ["*"],
"matches": ["<all_urls>"],
}],
"declarative_net_request": {
"rule_resources": [{
"id": "4399_rules",
"enabled": true,
"path": "dist/4399_rules.json"
}]
},

// Chrome runs the extension in a single shared process by default,
// which prevents extension pages from loading in Incognito tabs
Expand Down
8 changes: 8 additions & 0 deletions web/packages/extension/src/4399-content-script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
try {
Object.defineProperty(window, "showBlockFlash", {
value: () => {},
writable: false,
});
} catch (e) {
// Ignore.
}
2 changes: 2 additions & 0 deletions web/packages/extension/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default function (/** @type {Record<string, any>} */ env, _argv) {
background: "./src/background.ts",
player: "./src/player.ts",
pluginPolyfill: "./src/plugin-polyfill.ts",
siteContentScript4399: "./src/4399-content-script.ts",
},
output: {
path: url.fileURLToPath(new URL("assets/dist/", import.meta.url)),
Expand Down Expand Up @@ -130,6 +131,7 @@ export default function (/** @type {Record<string, any>} */ env, _argv) {
},
{ from: "LICENSE*" },
{ from: "README.md" },
{ from: "4399_rules.json" },
],
}),
],
Expand Down

0 comments on commit 036839f

Please sign in to comment.