Index: lib/cssInjection.js |
=================================================================== |
--- a/lib/cssInjection.js |
+++ b/lib/cssInjection.js |
@@ -21,19 +21,30 @@ |
const {RegExpFilter} = require("filterClasses"); |
const {ElemHide} = require("elemHide"); |
const {ElemHideEmulation} = require("elemHideEmulation"); |
const {checkWhitelisted} = require("whitelisting"); |
const {extractHostFromFrame} = require("url"); |
const {port} = require("messaging"); |
const devtools = require("devtools"); |
+const info = require("info"); |
-const userStyleSheetsSupported = "extensionTypes" in browser && |
- "CSSOrigin" in browser.extensionTypes; |
+const userStyleSheetsSupported = ("extensionTypes" in browser && |
+ "CSSOrigin" in browser.extensionTypes) || |
+ (info.platform == "chromium" && |
+ parseInt(info.platformVersion, 10) >= 66); |
+ |
+// Chromium's support for tabs.removeCSS is still a work in progress and the |
+// API is likely to be different from Firefox's; for now we just don't use it |
+// at all, even if it's available. |
+// See https://crbug.com/608854 |
+const styleSheetRemovalSupported = "removeCSS" in browser.tabs && |
+ info.platform == "gecko"; |
+ |
const selectorGroupSize = 1024; |
function* splitSelectors(selectors) |
{ |
// Chromium's Blink engine supports only up to 8,192 simple selectors, and |
// even fewer compound selectors, in a rule. The exact number of selectors |
// that would work depends on their sizes (e.g. "#foo .bar" has a size of 2). |
// Since we don't know the sizes of the selectors here, we simply split them |
@@ -67,16 +78,19 @@ |
frameId, |
matchAboutBlank: true, |
runAt: "document_start" |
}); |
} |
function removeStyleSheet(tabId, frameId, styleSheet) |
{ |
+ if (!styleSheetRemovalSupported) |
+ return; |
+ |
browser.tabs.removeCSS(tabId, { |
code: styleSheet, |
cssOrigin: "user", |
frameId, |
matchAboutBlank: true |
}); |
} |
@@ -137,16 +151,23 @@ |
if (!inline) |
updateFrameStyles(sender.page.id, sender.frame.id, selectors); |
let response = {trace, inline, emulatedPatterns}; |
if (trace || inline) |
response.selectors = selectors; |
+ // If we can't remove user style sheets using tabs.removeCSS, we'll only keep |
+ // adding them, which could cause problems with emulated filters as described |
+ // in issue #5864. Instead, we can just ask the content script to add styles |
+ // for emulated filters inline. |
+ if (!styleSheetRemovalSupported) |
+ response.inlineEmulated = true; |
+ |
return response; |
}); |
port.on("elemhide.injectSelectors", (message, sender) => |
{ |
updateFrameStyles(sender.page.id, sender.frame.id, message.selectors, |
message.groupName); |
}); |