web: Inject plugin polyfill immediately, on chrome/edge
This commit is contained in:
parent
7533923f9b
commit
2f9387f1ac
|
@ -48,6 +48,7 @@
|
||||||
"storage",
|
"storage",
|
||||||
"webRequest",
|
"webRequest",
|
||||||
"declarativeNetRequest",
|
"declarativeNetRequest",
|
||||||
|
"scripting",
|
||||||
],
|
],
|
||||||
"web_accessible_resources": [{
|
"web_accessible_resources": [{
|
||||||
"resources": ["*"],
|
"resources": ["*"],
|
||||||
|
|
|
@ -63,6 +63,24 @@ async function enable() {
|
||||||
removeRuleIds: [RULE_SWF_URL],
|
removeRuleIds: [RULE_SWF_URL],
|
||||||
addRules: rules,
|
addRules: rules,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await chrome.scripting.registerContentScripts([
|
||||||
|
{
|
||||||
|
id: "plugin-polyfill",
|
||||||
|
js: ["dist/pluginPolyfill.js"],
|
||||||
|
persistAcrossSessions: false,
|
||||||
|
matches: ["<all_urls>"],
|
||||||
|
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 {
|
} else {
|
||||||
(chrome || browser).webRequest.onHeadersReceived.addListener(
|
(chrome || browser).webRequest.onHeadersReceived.addListener(
|
||||||
onHeadersReceived,
|
onHeadersReceived,
|
||||||
|
@ -80,6 +98,9 @@ async function disable() {
|
||||||
await chrome.declarativeNetRequest.updateDynamicRules({
|
await chrome.declarativeNetRequest.updateDynamicRules({
|
||||||
removeRuleIds: [RULE_SWF_URL],
|
removeRuleIds: [RULE_SWF_URL],
|
||||||
});
|
});
|
||||||
|
await chrome.scripting.unregisterContentScripts({
|
||||||
|
ids: ["plugin-polyfill"],
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
(chrome || browser).webRequest.onHeadersReceived.removeListener(
|
(chrome || browser).webRequest.onHeadersReceived.removeListener(
|
||||||
onHeadersReceived,
|
onHeadersReceived,
|
||||||
|
|
|
@ -142,15 +142,13 @@ function isXMLDocument(): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must run the plugin polyfill before any flash detection scripts.
|
// 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
|
// NOTE: The script code injected here is the compiled form of
|
||||||
// plugin-polyfill.ts. It is injected by tools/inject_plugin_polyfill.js
|
// plugin-polyfill.ts. It is injected by tools/inject_plugin_polyfill.js
|
||||||
// which just search-and-replaces for this particular string.
|
// which just search-and-replaces for this particular string.
|
||||||
if (chrome) {
|
if (!chrome) {
|
||||||
await injectScriptURL(
|
// Chrome does this differently, by injecting it straight into the main world.
|
||||||
utils.runtime.getURL(`dist/pluginPolyfill.js?id=${ID}`),
|
// This isn't as fast, oh well.
|
||||||
);
|
|
||||||
} else {
|
|
||||||
injectScriptRaw("%PLUGIN_POLYFILL_SOURCE%");
|
injectScriptRaw("%PLUGIN_POLYFILL_SOURCE%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue