Index: lib/content/elemHideEmulation.js |
=================================================================== |
--- a/lib/content/elemHideEmulation.js |
+++ b/lib/content/elemHideEmulation.js |
@@ -448,20 +448,28 @@ |
// one of the patterns. |
return getCachedPropertyValue( |
this, "_dependsOnCharacterData", |
() => this.selectors.some(selector => selector.dependsOnCharacterData) |
); |
} |
}; |
-function filterPatterns(patterns, {stylesheets, mutations}) |
+function filterPatterns(patterns, {stylesheets, mutations}, document) |
{ |
if (!stylesheets && !mutations) |
+ { |
+ // On initial load, skip DOM-only patterns if it's the top frame, because |
+ // there's usually nothing interesting to see and we can respond to any |
+ // mutations later. |
+ if (typeof top != "undefined" && document.defaultView == top) |
hub
2018/03/23 14:58:59
Maybe I'm missing something, but where does that `
Manish Jethani
2018/03/23 16:56:46
That's a reference to the global variable window.t
hub
2018/03/24 01:02:14
I think it would be better, yes, both for clarity
|
+ return patterns.filter(pattern => pattern.dependsOnStyles); |
+ |
return patterns.slice(); |
+ } |
return patterns.filter( |
pattern => (stylesheets && pattern.dependsOnStyles) || |
(mutations && pattern.dependsOnDOM) |
); |
} |
function shouldObserveAttributes(patterns) |
@@ -572,17 +580,18 @@ |
* made reprocessing necessary. This parameter shouldn't be passed in for |
* the initial processing, the entire document will be considered |
* then and all rules, including the ones not dependent on the DOM. |
* @param {function} [done] |
* Callback to call when done. |
*/ |
_addSelectors(stylesheets, mutations, done) |
{ |
- let patterns = filterPatterns(this.patterns, {stylesheets, mutations}); |
+ let patterns = filterPatterns(this.patterns, {stylesheets, mutations}, |
+ this.document); |
let selectors = []; |
let selectorFilters = []; |
let elements = []; |
let elementFilters = []; |
let cssStyles = []; |
@@ -591,17 +600,17 @@ |
// do full processing. |
if (!stylesheets && !mutations) |
stylesheets = this.document.styleSheets; |
// If there are any DOM mutations and any of the patterns depends on both |
// style sheets and the DOM (e.g. -abp-has(-abp-properties)), find all the |
// rules in every style sheet in the document, because we need to run |
// querySelectorAll afterwards. On the other hand, if we only have patterns |
- // that depend on either styles or DOM both not both |
+ // that depend on either styles or DOM but not both |
// (e.g. -abp-properties or -abp-contains), we can skip this part. |
if (mutations && patterns.some(pattern => pattern.dependsOnStylesAndDOM)) |
stylesheets = this.document.styleSheets; |
for (let stylesheet of stylesheets || []) |
{ |
// Explicitly ignore third-party stylesheets to ensure consistent behavior |
// between Firefox and Chrome. |