Excerpt
This guide is designed to help you write and maintain your own Adblock Plus filters. Creating your own filters gives you more control over the things you want to see and don’t want to see on the we…
This guide is designed to help you write and maintain your own Adblock Plus filters. Creating your own filters gives you more control over the things you want to see and don’t want to see on the websites that you visit, including ads, images, requests, and scripts.
Important
All filter examples in this guide are only examples and are not meant to be used.
The following filter lists come pre-installed with Adblock Plus:
In addition to these pre-installed filter lists, you can create your own filters. A filter is simply a rule that tells your browser which elements to block. A filter list is a set of rules that tells your browser what to block.
There are several types of filters, or filter rules, including:
Blocking filters
Applied on the network level to decide whether a request should be blocked.
Content filters
(including hiding filters oftentimes referred to as element hiding filters)
Hide particular elements on a page, including element hiding with extended selectors (emulation) as well as snippets.
Exception filters
Used to unblock certain requests or unhide certain elements on certain websites. Additionally, they can allow certain network requests despite filters that would otherwise block the requests.
Note
Blocking and hiding filters can be set to negate or reverse the effects of other filters. These are then considered exception filters.
You can easily create your filter(s) via the Adblock Plus Settings page.
The most trivial filter you can define is the address of the request you want to block. However, this address often changes every time you open a page. For example, it could be http://example.com/ads/banner123.gif where 123 is a random number. Here, blocking the complete address won’t help. You’ll need a more general filter, like http://example.com/ads/banner*.gif, or even http://example.com/ads/, which blocks everything in the “ads” directory.
Note
Make sure that you don’t replace too much with wildcards. The filter http://example.com/ will block all banners, but it’ll also block everything else from example.com that you still might want to see.
If you notice that your filter is blocking something it shouldn’t, you might consider using an exception rule rather than removing or matching the filter. Exception rules allow you to define cases where filters shouldn’t be applied. Exception rules are no different from filter rules; you can use wildcards or regular expressions.
Example
If you are unhappy with your filter adv blocking http://example.com/advice.html, you can define an exception rule @@advice. You only need to precede it by @@ to indicate an exception rule.
Exception rules can do more, however. For example, if you specify $document option, you’ll get an exception for the entire page. If your exception rule is @@||example.com^$document and you open a page from example.com, Adblock Plus will be turned off on this page and nothing will be blocked.
Adblock Plus typically treats each filter as if it has a wildcard at its beginning and end (i.e. there’s no difference between the filters ad and *ad*). While this is usually unproblematic, sometimes you might want the filter you defined to only match at the beginning or the end of an address.
Example
You want to block all Flash, but if you add the filter swf, the address http://example.com/swf/index.html is also blocked. The solution is to add a pipe symbol ( |
) to the filter to show that there should be a definite end at this point. For example, the filter swf| blocks http://example.com/annoyingflash.swf but not http://example.com/swf/index.html. And the filter |http://baddomain.example/ blocks http://baddomain.example/banner.gif but not http://gooddomain.example/analyze?http://baddomain.example. |
You might want to block http://example.com/banner.gif as well as https://example.com/banner.gif and http://www.example.com/banner.gif. You can do this by putting two pipe symbols in front of the filter. This ensures that the filter matches at the beginning of the domain name: ||example.com/banner.gif, and blocks all of these addresses while not blocking http://badexample.com/banner.gif or http://gooddomain.example/analyze?http://example.com/banner.gif.
Sometimes, you might need to accept any separator character in a filter. For example, you might write a filter that blocks http://example.com/ and http://example.com:8000/ but not http://example.com.ar/. Here, the symbol ^ can be used as a placeholder for a single separator character, http://example.com^. The separator character can be anything but a letter, a digit, or one of the following: _, -, ., %. The end of the address is also accepted as a separator.
In the following example, all separator characters are shown bolded in blue:
http: // example.com : 8000 / foo.bar ? a = 12 & b = %D1%82%D0%B5%D1%81%D1%82
This address can be blocked with the filters ^example.com^ or ^%D1%82%D0%B5%D1%81%D1%82^ or ^foo.bar^.
Any rule that starts with an exclamation mark (!) is considered a comment. Adblock Plus ignores this rule for actual blocking, so it’s safe to write whatever you want in the comment. You can place a comment rule above a filter to describe its purpose or function, or you can place a comment above your filter list stating your authorship (most filter list authors do this).
Adblock Plus allows you to specify a number of options to modify the behavior of a filter. These options should be separated with a comma (,) after a dollar sign ($) at the end of the filter.
Example
/ads/*$script,match-case
Here, /ads/* is the actual filter, and script and match-case are its options. Currently, the following options are supported:
These determine which types of elements a filter can block (or allowlist in case of an exception rule). Multiple type options can be specified to indicate that the filter should be applied to several types of elements. Possible types include:
script - external scripts loaded via the HTML script tagimage - regular images, typically loaded via the HTML img tagstylesheet - external CSS stylesheet filesobject - content handled by browser plug-ins, e.g. Flash or Javaxmlhttprequest - requests started using the XMLHttpRequest object or fetch() APIsubdocument - embedded pages, usually included via HTML inline frames (iframes)ping - requests started by or navigator.sendBeacon() (Adblock Plus 2.7.1 or higher is required)websocket - requests initiated via WebSocket object (Adblock Plus 2.8 or higher is required)webrtc - connections opened via RTCPeerConnection instances to ICE servers (Adblock Plus 1.13.3 or higher for Chrome and Opera, 3.0 or higher for Firefox, is higher required)document - the page itself, but only works for exception rules. You can use this option to allowlist an entire iframe or website.elemhide - for exception rules only, similar to document but only turns off element hiding rules on the page rather than all filter rules (Adblock Plus 1.2 or higher is required)generichide - for exception rules only, similar to elemhide but only turns off generic element hiding rules on the page (Adblock Plus 2.6.12 or higher is required)genericblock - for exception rules only, just like generichide but turns off generic blocking rules (Adblock Plus 2.6.12 or higher is required)popup - pages opened in a new tab or window Note: Filters will not block pop-ups by default, only if the $popup type option is specified.font - external font filesmedia - regular media files like music and videoother - types of requests not covered in the list abovematch-case - ensures that the filter only applies to requests with matching letter case, e.g. the filter */BannerAd.gif$match-case blocks http://example.com/BannerAd.gif but not http://example.com/bannerad.gifThese specify which requesttypes the filter should not be applied to. Possible inverse type options include ~script, ~image, ~stylesheet, ~object, ~xmlhttprequest, ~subdocument, ~ping, ~websocket, ~webrtc, ~document, ~elemhide, ~other
If the third-party option is specified, the filter is only applied to requests from a different origin than the currently viewed page. Similarly, ~third-party restricts the filter to requests from the same origin as the currently viewed page.
The option domain=example.com means that the filter should only be applied on pages from the example.com domain. Multiple domains can be specified using | as the separator. For the option domain=example.com|example.net, the filter is only applied on pages from example.com or example.net domains. If a domain name is preceded with ~, the filter should not be applied on pages from this domain. For example, domain=~example.com means that the filter should be applied on pages from any domain but example.com and domain=example.com|~foo.example.com restricts the filter to the example.com domain with the exception of foo.example.com subdomain.
The option sitekey=abcdsitekeydcba means that the filter should only be applied on pages that provide a public key and a signature that can be verified by that very same public key that is also contained in the filter (but without the trailing =). Multiple sitekeys can be specified using | as a separator. For example, the option sitekey=abcdsitekeydcba|bcdesitekeyedcb only allows the filter to be applied on pages providing either sitekey abcdsitekeydcba or bcdesitekeyedcb. This is similar to domain restrictions, but allows for scenarios where a single filter should apply to a very large number of domains. Note: Sitekey restrictions require modifications on the server-side.
The option csp=script-src: 'none' causes a Content Security Policy header of script-src: 'none' to be injected into HTTP responses for requested documents matching the filter (assuming that exception rules with the same option don’t also match and that the document isn’t allowlisted). The Content Security Policy script-src: 'none' blocks all scripts, including inline, in the document. This filter option should generally be avoided, except as a last resort to counter advanced circumvention. (Adblock Plus 3.1 or higher is required.)
The rewrite= option allows the rewriting of URLs (or redirecting requests) to an internal resource in order to deactivate it without causing an error. Indicate the internal resource by name and prefix abp-resource: in order to be recognized. For example $rewrite=abp-resource:blank-js sends an empty JavaScript. (Adblock Plus 3.5 or higher required.) Available internal resources are:
blank-text - empty textblank-css - empty stylesheetblank-js - empty JavaScriptblank-html - empty HTML documentblank-mp3 - a 0.1s silent MP3 audio file1x1-transparent-gif - 1x1 pixel transparent GIF image2x2-transparent-png - 2x2 pixels transparent PNG image3x2-transparent-png - 3x2 pixels transparent PNG image32x32-transparent-png - 32x32 pixels transparent PNG imageAny other value will make the filter have no effect and let the request pass through.
rewrite= is restricted to certain domains using the $domain filter option. For more information, refer to the Domain restrictions section of this guide.rewrite= cannot be used together with the $third-party filter option, but can be used with $~third-party.* or start with ||.Adblock Plus supports filters written in regular expressions (regex). For example, the filter /banner\d+/ matches banner123 and banner321 but not banners. We recommend checking out Mozilla’s documentation on regular expressions to learn how to write them.
Note
For performance reasons, we recommend avoiding regular expressions if possible.
Special comments only have an effect in downloaded filter lists, not in custom filters. They can set a number of parameters for the filter list:
! Homepage: http://example.com/ - This comment determines which webpage should be linked as filter list homepage.! Title: FooList - This comment sets a fixed title for the filter list. If this comment is present, the user is no longer able to change the title.! Expires: 5 days - This comment sets the update interval for the filter list. The value can be given in days (e.g. 5 days) or hours (e.g. 8 hours). Any value between 1 hour and 14 days is possible. Note that the update will not necessarily happen after this time interval. The actual update time is slightly randomized and depends on some additional factors to reduce server load.! Redirect: http://example.com/list.txt - This comment indicates that the filter list has moved to a new download address. Adblock Plus ignores any file content beyond that comment and immediately tries downloading from the new address. In case of success, the address of the filter list is updated in the settings. This comment is ignored if the new address is the same as the current address, meaning that it can be used to enforce the “canonical” address of the filter list.! Version: 1234 - This comment defines a numerical version of the filter list. This version number is displayed in issue reports and can be used to verify that the report refers to the current version of the filter list.Unfortunately, there are some advertisements that can’t be blocked at download time. This is because they’re embedded as text in the webpage itself. For that case, there are filters that run directly on the content of the page. They are split between two main types: element hiding and snippets.
Element hiding filters are designed to indicate which element in the page are to be hidden.
Snippet filters are used to run snippets of code in the page to defeat more complex advertising display.
Content filters follow the following structure.