mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
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:
parent
3d24b89078
commit
73c2decdf5
2 changed files with 6 additions and 21 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue