Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include.preload.js

Issue 29679796: Issue 6298 - Split injected CSS hiding rule into groups of 1,024 selectors (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Update comment explaining why we split the selectors into groups of 1,024 Created Jan. 30, 2018, 1:39 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/cssInjection.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -348,17 +348,17 @@
this.emulatedPatterns = null;
this.elemHideEmulation = new ElemHideEmulation(
this.addSelectors.bind(this),
this.hideElements.bind(this)
);
}
ElemHide.prototype = {
- selectorGroupSize: 200,
+ selectorGroupSize: 1024,
createShadowTree()
{
// Use Shadow DOM if available as to not mess with with web pages that
// rely on the order of their own <style> tags (#309). However, creating
// a shadow root breaks running CSS transitions. So we have to create
// the shadow root before transistions might start (#452).
if (!("createShadowRoot" in document.documentElement))
@@ -425,21 +425,27 @@
preparedSelectors.push("::content " + subSelector);
}
}
else
{
preparedSelectors = selectors;
}
- // Safari only allows 8192 primitive selectors to be injected at once[1], we
- // therefore chunk the inserted selectors into groups of 200 to be safe.
- // (Chrome also has a limit, larger... but we're not certain exactly what it
- // is! Edge apparently has no such limit.)
- // [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69debb75fc1de/Source/WebCore/css/RuleSet.h#L68
+ // 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 into groups of 1,024, based on the reasonable
+ // assumption that the average selector won't have a size greater than 8.
+ // The alternative would be to calculate the sizes of the selectors and
+ // divide them up accordingly, but this approach is more efficient and has
+ // worked well in practice. In theory this could still lead to some
+ // selectors not working on Chromium, but it is highly unlikely.
+ // See issue #6298 and https://crbug.com/804179
for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize)
{
let selector = preparedSelectors.slice(
i, i + this.selectorGroupSize
).join(", ");
this.style.sheet.insertRule(selector + "{display: none !important;}",
this.style.sheet.cssRules.length);
}
« no previous file with comments | « no previous file | lib/cssInjection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld