From 97a33c957217acb7f1e3dae809558897d20952c2 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 27 Oct 2021 15:13:13 -0400 Subject: [PATCH] Fix test for stylesheet presence Related commit: - https://github.com/gorhill/uBlock/commit/4f923384de152fafaa52df8fa3e282cbe3db8659 --- src/js/static-filtering-parser.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index c22d01b26..1a477314e 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1442,13 +1442,16 @@ Parser.prototype.SelectorCompiler = class { // https://github.com/gorhill/uBlock/issues/3111 // Workaround until https://bugzilla.mozilla.org/show_bug.cgi?id=1406817 // is fixed. + // https://github.com/uBlockOrigin/uBlock-issues/issues/1751 + // Do not rely on matches() or querySelector() to test whether a + // selector is declarative or not. cssSelectorType(s) { if ( this.reSimpleSelector.test(s) ) { return 1; } const pos = this.cssPseudoElement(s); if ( pos !== -1 ) { return this.cssSelectorType(s.slice(0, pos)) === 1 ? 3 : 0; } - if ( this.div === null ) { return 1; } + if ( this.stylesheet === null ) { return 1; } try { this.stylesheet.insertRule(`${s}{color:red}`); if ( this.stylesheet.cssRules.length === 0 ) { return 0; }