From 0ce32af7af1e961a1e80d5e23b9cf6750f62e649 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sat, 25 Apr 2015 08:27:27 -0400 Subject: [PATCH] this fixes under-reporting of active cosmetic filters in logger --- src/js/contentscript-end.js | 8 +++++++- src/js/contentscript-start.js | 2 +- src/js/cosmetic-logger.js | 2 +- src/js/messaging.js | 7 +++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index ed2888060..67052b9b5 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -370,7 +370,7 @@ var uBlockCollapser = (function() { processHighHighGenericsAsync(); } } - if ( hideSelectors.length ) { + if ( hideSelectors.length !== 0 ) { addStyleTag(hideSelectors); } contextNodes.length = 0; @@ -687,6 +687,12 @@ var uBlockCollapser = (function() { idsFromNodeList(selectNodes('[id]')); classesFromNodeList(selectNodes('[class]')); retrieveGenericSelectors(); + + // This is required: a new element could be matching an already + // injected but otherwise inactive cosmetic filter. This means + // the already injected cosmetic filter become active (has an + // effect on the document), and thus must be logged if needed. + messager.send({ what: 'cosmeticFiltersActivated' }); } }; diff --git a/src/js/contentscript-start.js b/src/js/contentscript-start.js index 8bdc80cab..9b8131ccc 100644 --- a/src/js/contentscript-start.js +++ b/src/js/contentscript-start.js @@ -140,7 +140,7 @@ var filteringHandler = function(details) { // This is just to inform the background process that cosmetic filters were // actually injected. if ( vAPI.styles.length !== styleTagCount ) { - localMessager.send({ what: 'cosmeticFiltersInjected' }); + localMessager.send({ what: 'cosmeticFiltersActivated' }); } // https://github.com/chrisaljoudi/uBlock/issues/587 diff --git a/src/js/cosmetic-logger.js b/src/js/cosmetic-logger.js index f2c9f82e4..d038d1af6 100644 --- a/src/js/cosmetic-logger.js +++ b/src/js/cosmetic-logger.js @@ -68,10 +68,10 @@ while ( i-- ) { if ( loggedSelectors.hasOwnProperty(selector) ) { continue; } - loggedSelectors[selector] = true; if ( document.querySelector(selector) === null ) { continue; } + loggedSelectors[selector] = true; matchedSelectors.push(selector); } diff --git a/src/js/messaging.js b/src/js/messaging.js index 5fafafcdd..37ce13e0a 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -62,10 +62,9 @@ var onMessage = function(request, sender, callback) { break; case 'cosmeticFiltersInjected': - // Is this a request to cache selectors? - if ( Array.isArray(request.selectors) ) { - µb.cosmeticFilteringEngine.addToSelectorCache(request); - } + µb.cosmeticFilteringEngine.addToSelectorCache(request); + /* falls through */ + case 'cosmeticFiltersActivated': // Net-based cosmetic filters are of no interest for logging purpose. if ( µb.logger.isObserved(tabId) && request.type !== 'net' ) { µb.logCosmeticFilters(tabId);