Ensure procedural filters are applied at least once

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/discussions/2261#discussioncomment-4123057

Cosmetic filters will be applied unconditionally at least
once at DOMContentLoaded time.
This commit is contained in:
Raymond Hill 2022-11-12 11:22:49 -05:00
parent 3d24b89078
commit 73c2decdf5
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 6 additions and 21 deletions

View file

@ -441,8 +441,6 @@ PSelectorRoot.prototype.hit = false;
class ProceduralFilterer {
constructor(domFilterer) {
this.domFilterer = domFilterer;
this.domIsReady = false;
this.domIsWatched = false;
this.mustApplySelectors = false;
this.selectors = new Map();
this.masterToken = vAPI.randomToken();
@ -455,7 +453,7 @@ class ProceduralFilterer {
addProceduralSelectors(selectors) {
const addedSelectors = [];
let mustCommit = this.domIsWatched;
let mustCommit = false;
for ( const selector of selectors ) {
if ( this.selectors.has(selector.raw) ) { continue; }
let style, styleToken;
@ -483,9 +481,7 @@ class ProceduralFilterer {
}
commitNow() {
if ( this.selectors.size === 0 || this.domIsReady === false ) {
return;
}
if ( this.selectors.size === 0 ) { return; }
this.mustApplySelectors = false;
@ -567,8 +563,6 @@ class ProceduralFilterer {
}
onDOMCreated() {
this.domIsReady = true;
this.domFilterer.commit();
}
onDOMChanged(addedNodes, removedNodes) {

View file

@ -495,7 +495,6 @@ vAPI.DOMFilterer = class {
this.commitTimer = new vAPI.SafeAnimationFrame(
( ) => { this.commitNow(); }
);
this.domIsReady = document.readyState !== 'loading';
this.disabled = false;
this.listeners = [];
this.stylesheets = [];
@ -503,18 +502,6 @@ vAPI.DOMFilterer = class {
this.exceptions = [];
this.convertedProceduralFilters = [];
this.proceduralFilterer = null;
// https://github.com/uBlockOrigin/uBlock-issues/issues/167
// By the time the DOMContentLoaded is fired, the content script might
// have been disconnected from the background page. Unclear why this
// would happen, so far seems to be a Chromium-specific behavior at
// launch time.
if ( this.domIsReady !== true ) {
document.addEventListener('DOMContentLoaded', ( ) => {
if ( vAPI instanceof Object === false ) { return; }
this.domIsReady = true;
this.commit();
});
}
}
explodeCSS(css) {
@ -1241,6 +1228,10 @@ vAPI.DOMFilterer = class {
what: 'shouldRenderNoscriptTags',
});
if ( vAPI.domFilterer instanceof Object ) {
vAPI.domFilterer.commitNow();
}
if ( vAPI.domWatcher instanceof Object ) {
vAPI.domWatcher.start();
}