has-text selector does not work
It seems you do have support for the has-text selector?
https://github.com/brave/adblock-rust/blob/1bf068dbe186d89b3720c8c1ae59525ffde660fe/tests/unit/filters/cosmetic.rs#L714-L720
But this does not seem to work in Brave? Anything with :has-text(...) in it does not seem to parse correctly?
It's incredibly hard to tell what's going on - in the "block element" dialog, there is no indication of whether or not your selector is even valid. You can't tell if your selector has a syntax error, or it just doesn't match any elements. I don't understand how people develop or test filters for this ad blocker? Is this really the best/only tool we have for this?
(I want to block "Reels" on facebook, but there are literally no stable selectors to be had anywhere on the page - every single ID and class name are generated at build-time and will change with their next deployment. The only reasonably stable selector would be a text selector. I know this would have performance implications.)
Why was #588 rejected? (or was it? I see no comments?)
I know it can cause performance issues, but including the feature doesn't cause any performance issues if you don't ship any rules that use it - you can leave it to users if they think a slow rule is worth it or not, right?
This feature was standard in other ad blockers.
I desperately need this feature so I can block posts with em-dashes on Twitter.
@mindplay-dk :has-text(...) has been supported in Brave Browser since 2024, indeed using that css-validation feature. It isn't enabled by default in this library, but it also doesn't need to be because it is explicitly enabled in brave-core here.
If you're having trouble getting a certain filter rule to work, please share the rule, otherwise it's hard to say for sure what you're running into. My best guess at this point is that you're using a nested procedural filter (#495)?
It's incredibly hard to tell what's going on - in the "block element" dialog, there is no indication of whether or not your selector is even valid. You can't tell if your selector has a syntax error, or it just doesn't match any elements. I don't understand how people develop or test filters for this ad blocker? Is this really the best/only tool we have for this?
Debugging information has been a limitation, but this is the next focus of adblocking integration in Brave Browser. Hopefully we'll have some good news for you on that front relatively soon.
In the meantime, https://antonok.com/tmp/adblock-dashboard/index.html is a tool I created to help with at least seeing how a particular filter is interpreted by adblock-rust: you can see here it does recognize the HasText operator.
As soon as you add has-text to the selector, the UI appears to stop updating:
The red scribble is just spell check, I think? confusing in itself, but...
There is no syntax highlighting or error message for invalid selectors (which is a problem in itself) so it is hard to tell when it works or not - it just stops updating when the selector is invalid, I think? And any selector with has-text does not appear to be valid.
I also don't know what the unlabeled slider is for? are these just suggestions? this UI is very confusing.
Either way, rules with has-text also don't seem to work when inserted into an actual block list.
In the meantime, https://antonok.com/tmp/adblock-dashboard/index.html is a tool I created to help with at least seeing how a particular filter is interpreted by adblock-rust: you can see here it does recognize the
HasTextoperator.
Interestingly, this will parse google.com##button:has-text(Sponsored) but quietly fails to parse button:has-text(Sponsored), which makes me wonder if the issue is just with the block rule UI? I'd assume it adds the domain prefix itself though? The suggestions it generates don't have the domain prefix. (and rules without has-text do update the UI, so... idk...)
Looks like has-text() sometimes doesn't work when nested inside :has().
! Works
example.com##a:has-text("Learn more")
example.com##p:has-text("Learn more")
! Doesn't work
example.com##p:has(a:has-text("Learn more"))
In contrast, this rule does work in uBlock Origin.
Seeing issues with Brave 1.96.61 on Linux.
I'm unable to get has-text or matches-attr to work at all.
EX: on reddit.com/r/popular shreddit-post - Matches every post in the feed. OK good. shreddit-post:has-text("somevisibletexthere"). Matches don't update from last "successful" match. shreddit-post:matches-attr(subreddit-name="visiblesubredditname")). Matches nothing.
I then repeated the same experiment with a. a - matches every link on the page. a:has-text(...) matches nothing. a:matches-attr(href*="sometextfromthehref") matches nothing.
Yeah, it's easy to test this and find it doesn't work at all - pointing out what is or isn't enable in the source code is mostly moot, it does not work.
It's been broken for years. It takes one minute to test.
It would be nice if someone from the team would at least acknowledge the issue.
It would be nicer if this got fixed. 😊