1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-02 08:52:45 +01:00

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.
This commit is contained in:
Raymond Hill 2022-11-20 10:08:28 -05:00
parent 05a55afc48
commit 9b3ad0702c
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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);
}