I feel like filters based on id, class, attributes or node structure are not very effective because a website could easily randomize these in the backend.

I found myself countless times in a situation where I had no idea how I could possibly specify a filter to block a certain element.

I wonder if there is a sort of adblocker that can use more dynamic filters and maybe some sort of script support. So that you could for example check for an element with a certain aspect ratio or elements with an id that can be calculated mathematically.

At the moment I'm using Adblock Plus. My browser is Firefox.

1 Answer 1


The best stuff out there is uBlock Origin. It supports so-called "cosmetic filtering" in addition to run-of-the-mill static rules. Be sure to install the latest development release for that, though - the filtering language is getting closer and closer to being Turing-complete with each build.

Procedural cosmetic filters can now be chained and recursive (something which was planned) . Examples:

Chained: example.com##.item:matches-css-after(position: fixed):has-text(Promoted) Recursive: mobile.twitter.com##main [role="region"] > [role="grid"] > [role="rowgroup"] [role="row"]:if(div:last-of-type span:has-text(/^Promoted by/)) (actually a real use case).

There is no limit on the number of operators chained, or the number of recursion level, aside common sense. As a reminder, use procedural cosmetic filters only for when plain CSS selectors won't solve a case.

New procedural cosmetic filter operators:

:has-text(argument): to filter elements according to whether they have a specific text string found in them. Use /.../ to match a literal regular expression instead of plain text. :if()/:if-not(argument): use to implement recursion, argument is itself a valid procedural cosmetic filter, but can also be a plain CSS selector.

Any of the operator which accept a text string value to match can also accept of literal regular expression value.

The :xpath() operator can now accept a plain CSS selector as prefix (i.e. example.com##.item:xpath(...)), just like all other operators. The XPath evaluation will use whatever element matches the CSS selector as the context node for the XPath

If you feel it's insufficient, you can install uMatrix from the same author.

Disclaimer: I have no relationship to Gorhill, I'm simply awed by the guy's selfless work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.