From 036839fb1f382852711e0c1e270fa3e69a3a540a Mon Sep 17 00:00:00 2001 From: riku <75700668+riku-42@users.noreply.github.com> Date: Fri, 21 Jun 2024 23:05:53 +0800 Subject: [PATCH] extension: Fix 4399 CORS and Flash detection issue (close #13943) (#16750) Co-authored-by: Zhentao Lu --- web/packages/extension/4399_rules.json | 21 +++++++++++++++++++ web/packages/extension/manifest_other.json5 | 14 +++++++++++++ .../extension/src/4399-content-script.ts | 8 +++++++ web/packages/extension/webpack.config.js | 2 ++ 4 files changed, 45 insertions(+) create mode 100644 web/packages/extension/4399_rules.json create mode 100644 web/packages/extension/src/4399-content-script.ts diff --git a/web/packages/extension/4399_rules.json b/web/packages/extension/4399_rules.json new file mode 100644 index 000000000..42dbc687d --- /dev/null +++ b/web/packages/extension/4399_rules.json @@ -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" + } + ] + } + } +] diff --git a/web/packages/extension/manifest_other.json5 b/web/packages/extension/manifest_other.json5 index b86a6072e..8dc956564 100644 --- a/web/packages/extension/manifest_other.json5 +++ b/web/packages/extension/manifest_other.json5 @@ -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", } ], @@ -50,11 +56,19 @@ "permissions": [ "storage", "scripting", + "declarativeNetRequest", ], "web_accessible_resources": [{ "resources": ["*"], "matches": [""], }], + "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 diff --git a/web/packages/extension/src/4399-content-script.ts b/web/packages/extension/src/4399-content-script.ts new file mode 100644 index 000000000..d92bf00f8 --- /dev/null +++ b/web/packages/extension/src/4399-content-script.ts @@ -0,0 +1,8 @@ +try { + Object.defineProperty(window, "showBlockFlash", { + value: () => {}, + writable: false, + }); +} catch (e) { + // Ignore. +} diff --git a/web/packages/extension/webpack.config.js b/web/packages/extension/webpack.config.js index bd95dbab5..92f4d10f3 100644 --- a/web/packages/extension/webpack.config.js +++ b/web/packages/extension/webpack.config.js @@ -85,6 +85,7 @@ export default function (/** @type {Record} */ 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)), @@ -130,6 +131,7 @@ export default function (/** @type {Record} */ env, _argv) { }, { from: "LICENSE*" }, { from: "README.md" }, + { from: "4399_rules.json" }, ], }), ],