Skip to content

Commit

Permalink
Isolate generic cosmetic filters from specific ones in generated styl…
Browse files Browse the repository at this point in the history
…esheet

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.
  • Loading branch information
gorhill committed Nov 20, 2022
1 parent 05a55af commit 9b3ad07
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/js/cosmetic-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9b3ad07

Please sign in to comment.