diff --git a/web/packages/extension/manifest_other.json5 b/web/packages/extension/manifest_other.json5 index abc416792..ce44c9327 100644 --- a/web/packages/extension/manifest_other.json5 +++ b/web/packages/extension/manifest_other.json5 @@ -48,6 +48,7 @@ "storage", "webRequest", "declarativeNetRequest", + "scripting", ], "web_accessible_resources": [{ "resources": ["*"], diff --git a/web/packages/extension/src/background.ts b/web/packages/extension/src/background.ts index f482dbc94..038bd4f0b 100644 --- a/web/packages/extension/src/background.ts +++ b/web/packages/extension/src/background.ts @@ -63,6 +63,24 @@ async function enable() { removeRuleIds: [RULE_SWF_URL], addRules: rules, }); + + await chrome.scripting.registerContentScripts([ + { + id: "plugin-polyfill", + js: ["dist/pluginPolyfill.js"], + persistAcrossSessions: false, + matches: [""], + excludeMatches: [ + "https://sso.godaddy.com/*", + "https://authentication.td.com/*", + "https://*.twitch.tv/*", + "https://www.tuxedocomputers.com/*", + "https://*.taobao.com/*", + ], + runAt: "document_start", + world: "MAIN", + }, + ]); } else { (chrome || browser).webRequest.onHeadersReceived.addListener( onHeadersReceived, @@ -80,6 +98,9 @@ async function disable() { await chrome.declarativeNetRequest.updateDynamicRules({ removeRuleIds: [RULE_SWF_URL], }); + await chrome.scripting.unregisterContentScripts({ + ids: ["plugin-polyfill"], + }); } else { (chrome || browser).webRequest.onHeadersReceived.removeListener( onHeadersReceived, diff --git a/web/packages/extension/src/content.ts b/web/packages/extension/src/content.ts index e87d3cfe9..7fa1165f4 100644 --- a/web/packages/extension/src/content.ts +++ b/web/packages/extension/src/content.ts @@ -142,15 +142,13 @@ function isXMLDocument(): boolean { } // We must run the plugin polyfill before any flash detection scripts. - // Unfortunately, this might still be too late for some websites when using Chrome (issue #969). + // Unfortunately, this might still be too late for some websites (issue #969). // NOTE: The script code injected here is the compiled form of // plugin-polyfill.ts. It is injected by tools/inject_plugin_polyfill.js // which just search-and-replaces for this particular string. - if (chrome) { - await injectScriptURL( - utils.runtime.getURL(`dist/pluginPolyfill.js?id=${ID}`), - ); - } else { + if (!chrome) { + // Chrome does this differently, by injecting it straight into the main world. + // This isn't as fast, oh well. injectScriptRaw("%PLUGIN_POLYFILL_SOURCE%"); }