Index: lib/cssInjection.js |
=================================================================== |
--- a/lib/cssInjection.js |
+++ b/lib/cssInjection.js |
@@ -24,16 +24,35 @@ |
const {ElemHideEmulation} = require("elemHideEmulation"); |
const {checkWhitelisted} = require("whitelisting"); |
const {extractHostFromFrame} = require("url"); |
const {port} = require("messaging"); |
const devtools = require("devtools"); |
const userStyleSheetsSupported = "extensionTypes" in browser && |
"CSSOrigin" in browser.extensionTypes; |
+const selectorGroupSize = 200; |
+ |
+function createStyleSheet(selectors) |
+{ |
+ let styleSheet = ""; |
+ |
+ // Chromium's Blink engine supports only up to 8,192 selectors; more |
kzar
2018/01/25 17:46:47
If we're limited to 8192 why do we go with 200?
Manish Jethani
2018/01/25 18:42:41
It's "up to 8,192" selectors.
If you have 8,192 s
Manish Jethani
2018/01/25 18:44:28
This was not technically true by the way but now [
Manish Jethani
2018/01/30 06:19:43
Now that I think about it, maybe we should increas
kzar1
2018/01/30 11:39:59
Sounds good to me, but let's rewrite the comment t
Manish Jethani
2018/01/30 13:15:43
Unfortunately this comment is confusing and techni
|
+ // specifically, it ignores any selectors that start at index 8192 or beyond |
+ // in the list of plain selectors. In order to avoid spilling outside of this |
+ // range, we simply add multiple rules in groups of up to 200 selectors each. |
+ // See issue #6298 and https://crbug.com/804179 |
+ for (let i = 0; i < selectors.length; i += selectorGroupSize) |
+ { |
+ styleSheet += selectors.slice(i, i + selectorGroupSize).join(", ") + |
+ " {display: none !important;}\n"; |
+ } |
+ |
+ return styleSheet; |
+} |
function addStyleSheet(tabId, frameId, styleSheet) |
{ |
browser.tabs.insertCSS(tabId, { |
code: styleSheet, |
cssOrigin: "user", |
frameId, |
matchAboutBlank: true, |
@@ -50,17 +69,17 @@ |
matchAboutBlank: true |
}); |
} |
function updateFrameStyles(tabId, frameId, selectors, groupName) |
{ |
let styleSheet = null; |
if (selectors.length > 0) |
- styleSheet = selectors.join(", ") + "{display: none !important;}"; |
+ styleSheet = createStyleSheet(selectors); |
let frame = ext.getFrame(tabId, frameId); |
if (!frame.injectedStyleSheets) |
frame.injectedStyleSheets = new Map(); |
let oldStyleSheet = frame.injectedStyleSheets.get(groupName); |
// Ideally we would compare the old and new style sheets and skip this code |