I have a content blocker that generally works correctly, but I need to block an element that has certain text in it.
For example, <span id="theId">Some text</span>
is easy enough to block because I can locate the id
and block that, but what if there is no id
, or the id
is completely random? What if it's just <span>Some text</span>
? How do I block that?
Let's say this is my only content blocker rule:
[
{
"action": {
"type": "css-display-none",
"selector": ":has-text(/Some text/i)"
},
"trigger": {
"url-filter": ".*"
}
}
]
No errors are seen when the rule is loaded, so it's syntactically correct, it just doesn't block the HTML. I gather this is because :has-text()
works on attributes, not contents, so it works on alt
, href
, aria-label
etc. but not on the contents of the element itself.
How do I block Some text
in my example above? Thanks!