From 9b3ad0702cbfadb586c251da6005d125e3567ad4 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 20 Nov 2022 10:08:28 -0500 Subject: [PATCH] Isolate generic cosmetic filters from specific ones in generated stylesheet Related feedback: - https://www.reddit.com/r/uBlockOrigin/comments/yzw5pt/ Some CSS4-based selectors are not supported in older browser versions and this may cause cosmetic filtering to be wholly broken as a result. The commit here is to isolate generic cosmetic filters from specific ones in stylesheets such that unsupported CSS4 selectors in generic cosmetic filters do not cause wholly breakage of cosmetic filtering on all sites. --- src/js/cosmetic-filtering.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index c677c8f2c..466947fc0 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -980,7 +980,6 @@ FilterContainer.prototype.retrieveSpecificSelectors = function( options.noSpecificCosmeticFiltering !== true || options.noGenericCosmeticFiltering !== true ) { - const injectedHideFilters = []; const specificSet = this.$specificSet; const proceduralSet = this.$proceduralSet; const exceptionSet = this.$exceptionSet; @@ -1040,7 +1039,9 @@ FilterContainer.prototype.retrieveSpecificSelectors = function( } if ( specificSet.size !== 0 ) { - injectedHideFilters.push(Array.from(specificSet).join(',\n')); + injectedCSS.push( + `${Array.from(specificSet).join(',\n')}\n{display:none!important;}` + ); } // Some procedural filters are really declarative cosmetic filters, so @@ -1091,17 +1092,11 @@ FilterContainer.prototype.retrieveSpecificSelectors = function( out.exceptedFilters.push(...str.excepted); } if ( str.s.length !== 0 ) { - injectedHideFilters.push(str.s); + injectedCSS.push(`${str.s}\n{display:none!important;}`); } } } - if ( injectedHideFilters.length !== 0 ) { - injectedCSS.push( - `${injectedHideFilters.join(',\n')}\n{display:none!important;}` - ); - } - // Important: always clear used registers before leaving. specificSet.clear(); proceduralSet.clear(); @@ -1130,7 +1125,7 @@ FilterContainer.prototype.retrieveSpecificSelectors = function( const networkFilters = []; cacheEntry.retrieve('net', networkFilters); if ( networkFilters.length !== 0 ) { - details.code = networkFilters.join('\n') + '\n{display:none!important;}'; + details.code = `${networkFilters.join('\n')}\n{display:none!important;}`; if ( request.tabId !== undefined ) { vAPI.tabs.insertCSS(request.tabId, details); }