Snippet filters tutorial

This guide is aimed at filter authors and advanced users that want to make the most out of Adblock Plus. It's a companion to the guide on writing filters that covers snippet filters. While it's recommended that you be familiar with writing filters, you should be OK otherwise. You don't need a deep knowledge of JavaScript, but you need to be familiar with it, as well as with web technologies like HTML, CSS, and the DOM. If you really want, Mozilla has a great resource to learn JavaScript, HTML and CSS.

This guide doesn't cover how to write an actual snippet, i.e. the JavaScript code that is loaded by Adblock Plus into the browser when you execute a snippet filter. This requires modifying the extension, and it will be covered in an upcoming developer guide.

Table of contents

What are snippet filters?

Snippet filters are a new type of filter introduced in Adblock Plus 3.3 that allows running specialized code snippets (written in JavaScript) on pages within a list of specified domains. These snippets are selected from an existing library available in Adblock Plus.

The snippet approach allows interfering with ad display code in a more efficient manner, and also allows locating elements to hide in a way that can't be expressed with CSS or the current advanced selectors.

For security reasons, snippet filters can only be added to a user's custom filters list or in the ABP Anti-Circumvention Filter List, the latter being vetted and reviewed.

Syntax

The basic syntax of a snippet filter is as follows:

https://eyeo.atlassian.net/wiki/download/attachments/1827831992/69c2d5c7d467f.13582352421651.png?version=1&modificationDate=1774376391958&cacheVersion=1&api=v2

You can run several snippets in the same filter by separating them with a ;. See example 6.

Arguments

Arguments are strings. They can be surrounded by single quotes (') if they contain spaces. To have a single quote ' as part of the argument, escape it like this: \' ; you can also escape spaces with \ instead of quoting the argument. See examples 3a, 3b and 3c.

You can input Unicode characters by using the syntax \uNNNN, where NNNN is the Unicode codepoint. See example 4.

You can also input carriage return, line feed, and tabs using \r, \n, and \t, respectively. To have a \ in an argument, including a regular expression, it must be escaped with \, i.e. doubled up. See example 5.

Examples

Basic snippet filter syntax

These examples demonstrate the syntax of a snippet filter and how to pass arguments. While we mostly use the log snippet, these examples apply to other snippet functions as well.

Example 1

example.com#$#log Hello

This prints “Hello” in the web console on the domain example.com and its subdomains.

Example 2

anotherexample.com,example.com#$#log Hello

Same as example 1, but “Hello” also appears on the domain anotherexample.com. Like with other filter types, multiple domains should be separated by commas ,.

This filter makes the filter in example 1 obsolete. Having both filters makes the message appear twice on example.com, as both would be run.

Example 3a

example.net,example.com#$#log 'Hello from an example to another example'

This is a different message from example 2. Because it contains spaces, the string must be surrounded with single quotes '.

Example 3b

example.net,example.com#$#log 'Hello it\'s me again'

This shows the escape sequence for having a single quote, using \'.

Example 3c

example.net,example.com#$#log Hello\ no\ quotes

You can also escape spaces instead of quoting the argument, using \.

Example 4

emoji.example.com#$#log \u1F601

On the domain emoji.example.com, the emoji 😀 is printed in the console. The filter will not be run on example.com or www.example.com. This shows how to use escape for Unicode symbols.

Example 5

emoji.example.com#$#log '\u1F601\nand a new line'

This is similar to example 4, except that the filter prints the emoji 😀 and then on a new line, prints and a new line. This shows how to use escape for Unicode symbols, as well as adding a new line.

Example 6

Running two snippets:

debug.example.com#$#debug; log 'This should be prefixed by DEBUG'

First, we see debug. This is the snippet that enables debugging. It's just like any other snippet. Then we see log, whose output is modified when debugging is enabled. See the section on debugging for more details.

example.com#$#log 'Always log'; log 'And better twice than once'

This is another example of logging two lines. Here the snippet command will be called twice.

Debugging

We saw a debug snippet in Example 6. Its use is simple: calling debug before a snippet turns on the debug flag. If the other snippets support it, they'll enable their debug mode. What a snippet does in debug mode is up to the snippet.

debug

Since: Adblock Plus 3.8

Enables the debug mode for all the snippets that come after the debug snippet in the filter's snippets chain.

Filter Result
debug; log OK logs OK to the console with a preceded by a DEBUG word
debug; abort-on-property-read atob activates debug mode for the abort-on-property-read snippet
debug hello; snippet-name Only prints debug logs that contain the word hello.
debug /json-prune\|json-override/; snippet-name Only prints logs coming from the json-prune or json-override snippets.

log

Since: Adblock Plus 3.3

Logs its arguments to the console. This may be used for testing and debugging.

Filter Result
log OK logs OK to the console
log Hello, world! logs Hello, World! to the console (with 2 parameters)
log 'Hello, world!' logs Hello, World! to the console (with 1 parameter)

profile

Since: Adblock Plus 4.8

It executes using the Performance API. It marks specific points (the beginning and the end in the main logic of every snippet) and measures the time taken between these points (duration).

The duration is expressed in ms.

It logs an object with the performance data of the monitored snippet.

Filter Result
profile; abort-on-property-read atob activates profile mode for the abort-on-property-read snippet and will log its performance regardless of whether the snippet runs successfully or fails.
profile; debug; abort-on-property-read atob activates debug mode for the abort-on-property-read snippet

trace

Since: Adblock Plus 3.3

Similar to log, but does the logging in the context of the document rather than the content script.

This may be used for testing and debugging, especially to verify that the injection of snippets into the document is working without any errors.

Filter Result
trace OK logs OK to the console
trace Hello, world! logs Hello, World! to the console (with 2 parameters)
trace 'Hello, world!' logs Hello, World! to the console (with 1 parameter)

Performance

Snippet that aim to reduce the performance overhead caused by using other snippets.

race

“racing” mechanism among snippets that can easily compete against each other:

  • snippets based on the same environment (in this case, the isolated world)
  • snippets able to signal a winning strategy, but also able to stop executing.
Name Description Mandatory
race start; Begins a race, passing arbitrary amount of winners which, by default, is 1. yes
race stop; Stops a race. yes
Filter Result
!# snippet, another, first, etc example.com#$#race start; snippet 1 2 3; other 4 5 6; another 7 8 9; race stop; example.com#$#race start 2; first 1; second 2; third 3; fourth 4; race stop; Whatever snippet “wins” the race, all others will be flagged as “loosers”, and their registered callback to stop them executing, will be invoked.

Behavioral Snippets

Snippets that change the normal execution behavior of the page.

abort-current-inline-script

Since: Adblock Plus 3.4.3

Aborts the execution of an inline script when a property is either read or written.

Name Description Mandatory
api API function or property name to anchor on. It can also be the path to that property. If the property is a direct child of window, this parameter will be just the property name. But, if you want to access a sub property, this parameter will be a chain of properties separated by dots. yes
search If specified, only scripts containing the given string are prevented from executing. If the string begins and ends with a slash (/), the text in between is treated as a regular expression. no

abort-on-property-read

Since: Adblock Plus 3.4.1

Patches a property on the window object to abort execution when the property is read.

No error is printed to the console.

The idea originates from .

Name Description Mandatory
property The name of the property or the path to that property. If the property is a direct child of window, this parameter will be just the property name. But, if you want to access a sub property, this parameter will be a chain of properties separated by dots. yes
setConfigurable Value of the configurable attribute of the descriptor of property. If this parameter is not used it defaults to true. Setting it to false will prevent the property set and get being overwritten or otherwise changed by anybody. If this snippet doesn't work as expected when passing only the property, it could mean that the website is circumventing and setting this parameter to false can come in handy. no

abort-on-property-write

Since: Adblock Plus 3.4.3

Patches a property on the window object to abort execution when the property is written.

No error is printed to the console.

The idea originates from .

Name Description Mandatory
property The name of the property or the path to that property. If the property is a direct child of window, this parameter will be just the property name. But, if you want to access a sub property, this parameter will be a chain of properties separated by dots. yes
setConfigurable Value of the configurable attribute of the descriptor of property. If this parameter is not used it defaults to true. Setting it to false will prevent the property set and get being overwritten or otherwise changed by anybody. If this snippet doesn't work as expected when passing only the property, it could mean that the website is circumventing and setting this parameter to false can come in handy. no

abort-on-iframe-property-read

Since: Adblock Plus 3.10.1

Patches a list of properties on the iframes' window object to abort execution when the property is read.

No error is printed to the console.

Name Description
properties The list with the properties we want to abort on.

abort-on-iframe-property-write

Since: Adblock Plus 3.10.1

Patches a list of properties on the iframes' window object to abort execution when the property is written.

No error is printed to the console.

Name Description
properties The list with the properties we want to abort on.

array-override

Since: Adblock Plus 4.8

Overrides functions under Array.prototype to change their behaviour according to the given parameters.

Name Description Mandatory Default value
method The Array function to override. Possible values to override the property with:push,includes, forEach yes n.a.
needle The string or regex used to determine which function calls to trap. If the needle matches the parameter to the function call, the snippet will work, else the function will behave as normal. If the string begins and ends with a slash ( / ), the text in between is treated as a regular expression. yes n.a.
returnValue Optional parameter that is only relevant for includes. This parameter determines what to return when the parameter matches the needle. Accepts: true or false. Default is false. no false
path Optional parameter that enables “object checking mode“ and looks for needle in that given path. Example: arr.push({obj: {child: “test”}}) if you want to ignore this call, path would be obj.child in this case and needle would be test no ''
stack Comma separated list of strings to check in the stack trace. If provided, the override will only apply when the stack trace contains at least one of these patterns. no ''

blob-override

Since: Adblock Plus 4.22.2

Overrides specific parts of the Blob injected in web-pages. We override the blob constructor in a way we can intercept calls and change the blob content.

Name Description Mandatory Default value
search The string or regex pattern to match in the blob content. yes n.a.
replacement The string to replace the matched pattern with. no ''
needle An optional string or regex to check in the * blob parts before applying the replacement. no ''

Since: Adblock Plus 3.11.2

A snippet to remove certain cookies.

Name Description Mandatory
cookie Pattern that matches the name of the cookie(s) we want to remove. If the string starts and ends with a slash (/), the text in between is treated as a regular expression. yes
autoRemoveCookie Default value:  false. When set to true, this parameter enables the snippet to continuously monitor the targeted cookie, checking for its presence every 1000 ms.  If the cookie is found, it will be repeatedly removed. To use only in case the website sets back the cookie after removal. no

event-override

Since: Adblock Plus 4.22.2

Proxies events and event handlers to defuse events or change their attributes. It works with the principle of proxying addEventListener function and the original Event class with a CustomEvent class that we control. This way we can defuse/change any arbitrary event or create new ones.

Name Description Mandatory Default value
eventType The type of the event to target. Examples: click, mouseover, someCustomEvent. yes n.a.
mode The mode of the operation. Accepts: “trusted“, “disable“, “rewrite“. trusted mode makes the event property isTrusted true. disable mode: Disables the matching event. rewrite mode: replaces text inside a named string property of the event. yes n.a.
needle Needle to look for in the event listener function's source, not in the event payload no ''
property rewrite mode only. The name of the event property to rewrite, e.g. data. only in rewrite mode null
pattern rewrite mode only. Regex or literal text matched against the property value. Every match is replaced. only in rewrite mode null
replacement rewrite mode only. The replacement text. Empty deletes the matched text. no ''

freeze-element

Since: Adblock Plus 3.10

Freezes a DOM element so it prevents adding new nodes inside it.

Name Description Example Mandatory
selector The CSS selector for the parent element that we want to freeze '.left-content .container' yes
options A single parameter for snippet's options. A string containing all the options we want to pass, each of them separated by a plus character (+). Empty single quotes if none ('') Available options: •subtree (if we want to freeze all the element's children as well) •abort (throw an error every time an child element gets added) '' orsubtree or abort or subtree+abort etc. no
exceptions An array of regex/selectors used to specify the nodes we don't want to prevent being added. Each array item can be: •selector (targeting Element nodes) •regex (targeting Text nodes, identified by slash) .article #banner .navigation /.*/ no

json-override

Since: Adblock Plus 3.11.2

It's very similar to json-prune, but instead of removing a property, we override it with a value from the same list as for override-property-read.

It wraps both JSON.parse and Response.prototype.json, so a payload read with await response.json() is covered too.

Name Description Mandatory
rawOverridePaths A list of space-separated properties to override. It also accepts property chains - e.g. foo.bar.tar. Can include placeholders {} and [] to iterate over nested objects and arrays respectively. Each entry can also be a jsonpath(...) query. The {-} and [-] removal placeholders json-prune accepts are not supported here. yes
value The value to override the property with (see below for possible values) yes
rawNeedlePaths A list of space-separated properties which must be all present for the override to occur. It also accepts property chains. no
filter A string to look for in the raw string, before it's passed to JSON.parse. If no match is found no further search is done on the resulting object. If the string begins and ends with a slash (/), the text in between is treated as a regular expression. no

Possible values

The value argument accepts the same list as override-property-read:

value meaning
undefined
false false as a boolean
true true as a boolean
falseStr “false“ as a string
trueStr “true” as a string
null
noopFunc function with empty body
trueFunc function returning true
falseFunc function returning false
emptyArray An array with no elements
emptyObj An object with no properties
'' empty string
positive decimal integer
Any arbitrary string that doesn’t match the values above

json-prune

Since: Adblock Plus 3.9.0

Traps calls to JSON.parse, and if the result of the parsing is an Object, it will remove specified properties from the result before returning to the caller.

It wraps both JSON.parse and Response.prototype.json, so a payload read with await response.json() is covered too.

The idea originates from uBlock Origin.

Name Description Mandatory
rawPrunePaths A list of space-separated properties to remove. Can include placeholders {} and [] to iterate over nested objects and arrays respectively. Each entry can also be a jsonpath(...) query. yes
rawNeedlePaths A list of space-separated properties which must be all present for the pruning to occur. no
rawNeedleStack A list of space-separated strings or regex which must be present in the JSON.prune call stack for the pruning to occur. no

map-override

Since: Adblock Plus 4.24.0

Overrides functions under Map.prototype to change their behaviour according to the given parameters.

Name Description Mandatory Default value
method The Map function to override. Possible values to override the property with: set, get, has yes n.a.
needle The string or regex used to determine which function calls to trap. If the needle matches the parameter to the function call, the snippet will work, else the function will behave as normal. If the string begins and ends with a slash (/), the text in between is treated as a regular expression. For 'set' this matches the value. For 'get' and 'has' this matches the key. yes n.a.
returnValue The return value for the matched function calls. For 'set' ignored. For 'get' the value to return. For 'has', true or false. no ''
path Path to look for the needle. Only relevant for 'set' method when checking for object values. no ''
stack Comma separated list of strings to check in the stack trace. If provided, the override will only apply when the stack trace contains at least one of these patterns. no ''

override-property-read

Since: Adblock Plus 3.9.4

Overrides a property's value on the window object with a set of available properties.

The idea originates from .

Name Description Mandatory
property The name of the property or the path to that property. If the property is a direct child of window, this parameter will be just the property name. But, if you want to access a sub property, this parameter will be a chain of properties separated by dots. yes
value The value to override the property with. yes
setConfigurable Value of the configurable attribute of the descriptor of property. If this parameter is not used it defaults to true. Setting it to false will prevent the property set and get being overwritten or otherwise changed by anybody. If this snippet doesn't work as expected when passing only the property and the value, it could mean that the website is circumventing and setting this parameter to false can come in handy. no

prevent-listener

Since: Adblock Plus 3.11.2

Prevents adding event listeners.

Wrap EventTarget.prototype.addEventListener and don't allow adding listeners for certain types of events.

Name Description Mandatory
type Pattern that matches the type(s) of event we want to prevent. If the string starts and ends with a slash (/), the text in between is treated as a regular expression. yes
handler Pattern that matches the event handler's declaration. If the string starts and ends with a slash (/), the text in between is treated as a regular expression. no
selector The CSS selector that the event target must match. If the event target is not an HTML element the event handler is added. no

replace-fetch-response

Since: Adblock Plus 4.4

Replaces the response of a fetch request if the response text matches a given regular expression pattern.

Name Description Mandatory Default value
search String or regex pattern that will be run against the stringified fetch response. Everything that matches the regex will be replaced with the replacement value. yes n.a.
replacement Everything that matches the regex will be replaced with the replacement value. By default this will be an empty string, so everything that matches the regex will be removed from the fetch response. no empty string
needle The replacement will only happen if the needle text is present in the response. By default this is an empty string. If the string begins and ends with a slash (/), the text in between is treated as a regular expression. no empty string

replace-outbound-value

Since: Adblock Plus 4.26.0

Overrides return values of functions or attributes according to the given parameters.

Name Description Mandatory Default value
method The method to trap. This could be any function or attribute that is accessible under window. e.g.JSON.stringify, atob... yes n.a.
search The text or regex pattern to replace yes n.a.
replacement The replacement text no empty string
decodeMethod The decode method. When provided the snippet can decode the encoded text before replacing it. Useful for functions like btoa. Currently only “base64” is supported. no empty string
path Dot-separated path to the property in returned objects. Can be used to override return values for functions that return objects instead of primitive strings. If left empty, only functions that return strings will be tackled. e.g. user.profile.name. no empty string
stack Comma-separated list of strings to check in the stack trace. If provided the replacement will only apply when the stack trace contains at least one of these patterns. no empty string

replace-xhr-response

Since: Adblock Plus 4.4

Replaces the response of a XHR request if the response text matches a given regular expression pattern.

Name Description Mandatory Default value
search String or regex pattern that will be run against the stringified XHR response. Everything that matches the regex will be replaced with the replacement value. If the value starts with jsonpath(, it is treated as a JSONPath query instead. yes n.a.
replacement Everything that matches the regex will be replaced with the replacement value. By default this will be an empty string, so everything that matches the regex will be removed from the XHR response. In JSONPath mode it is interpreted as a typed value from the same list as override-property-read, not as literal text. no empty string
needle The replacement will only happen if the needle text is present in the response. By default this is an empty string. If the string begins and ends with a slash (/), the text in between is treated as a regular expression. no empty string

prevent-element-src-loading

Since: Adblock Plus 4.35.1

Prevents targeted elements (script, img, iframe, link) from loading specific resources by intercepting src/href assignments and redirecting them to local mock data. It also neutralizes onerror handlers and error event listeners to ensure the loading fails silently without triggering errors/walls.

Name Description Mandatory Default value
tagName The type of HTML element to target. Accepted values: script, img, iframe, link yes n.a.
search The string or regex used to match the URL in the src (for scripts/imgs/iframes) or href (for links). If the string begins and ends with a slash ( / ), it is treated as a regular expression. yes n.a.

timer-override

Since: Adblock Plus 4.36

Changes the behaviour of setTimeout and setInterval calls on a page. It can make timers fire sooner or much later than intended, or disable the callback entirely.

Name Description Mandatory
timerValue New timer delay in milliseconds. yes
needle Only override calls whose parameters (callback source or delay) match this string or regex. no
mode Which timer type to override: “timeout”, “interval”, or “both” (default). no
callbackFunc Pass “noop” to replace the callback with a no-operation function instead of just changing the delay. no
stackNeedle Space-separated strings or regexes that must appear in the call stack for the override to apply. no

replace-xhr-request

Since: Adblock Plus 4.36

Intercepts and modifies outgoing XHR request bodies before they reach the server.

Name Description Mandatory
search String or regex to match in the request body. Use jsonpath( prefix for targeted JSON property replacement. yes
replacement Value to replace the match with. In JSONPath mode, parsed via JSON.parse (e.g. “false” becomes false). Default: “”. no
needle Optional regex to pre-filter requests — replacement only runs if this matches the body. Default: none. no
mode JSONPath operation mode: “replace” (default) overwrites the property; “append” merges or concatenates based on data type. no

simulate-mouse-event

Since: Adblock Plus 3.17

Triggers arbitrary mouse events on elements that are matched by a CSS or Xpath selector, by calling dispatchEvent for a selector.

Name Description Mandatory
selectors The CSS/Xpath selector that an HTML element must match for the event to be triggered. Maximum 7 selectors are supported. Take a look at the optional parameters and the examples below for the explanation of how they should be written. yes

Optional parameters are added to the selectors with a $ sign. Multiple parameters can be combined for a single selector by separating them with a comma. If a parameter is not specified, the default value will be assumed for that selector.

Name Description Default Mandatory
$trigger If this flag is not set, only the chosen event for the last selector will be triggered. $trigger flag can be used for the other selectors to make sure the event is triggered for them as well. $trigger is always true for the last selector so can be omitted for it. false no
$delay Determines how much time the snippet should wait before simulating the even. Note that the default is 500 ms. If you don't want to have a delay, you should explicitly state $delay=0. 500 no
$continue If set, the event will be triggered after each delay period ends. For example, if the selected event is click and the delay is 500 ms. The click event will be triggered every 500 ms instead of just once. false no
$event Determines which event should be simulated for the selector. click no
Filter Result
simulate-mouse-event 'some-css-selector' Simulates a click event for the eleents that match the selector after 500 ms.
simulate-mouse-event 'css-selector1' 'css-selector2' Simulates a click event for css-selector2 only if the css-selector1 is present in the page. Does not click css-selector1.
simulate-mouse-event 'css-selector1$trigger' 'css-selector2' Simulates a click event for both of the selectors if both of them are present in the page. Note that the $trigger parameter for css-selector2 can be omitted as it is the last parameter.
simulate-mouse-event 'xpath(some-xpath-selector)$delay=0' Simulates a click event for the elements that are matched with the xpath selector with no delay.
simulate-mouse-event 'some-css-selector$continue,delay=100' Simulates a click event every 100 ms.
simulate-mouse-event 'some-css-selector$continue,delay=100, event=mouseover' Simulates a mouseover (hover) event over all the elements matching the selector every 100 ms.

As you can see the you can mix and match the parameters to create the filter that best suits the case. The parameters doesn't have any order $delay=100,trigger is the same as $trigger,delay=100.

skip-video

Since: Adblock Plus 3.21

Makes the video skip to its end or fast forwards it with the given amount. It does it by setting the currentTime attribute of the video object.

Name Description Mandatory Default Value
playerSelector The CSS or the XPath selector to the element in the page. Yes -
xpathCondition The XPath selector that will be used to know when to trigger the skipping logic. Yes -
optionalParameters Optional parameters to configure the snippet. Any number of the supported parameters from the table below can be added to this in any order. Separate the optional parameters with space as if they are different arguments to the filter. No
Name Description Default Value Example
-skip-to Determines the time of the video to skip to. If the value is zero or negative, the snippet skips to the end of the video (video.currentTime = video.duration + skipTo). If the skipTo value is positive, the snippets skips the video by the given value (video.currentTime = video.currentTime + skipTo). A small negative value like (-0.1) or zero is preferred for most of the cases as it would cause the video to nearly instantly end. Large positive values can be used to quickly fast forward a video (5-10 seconds at a time) to better mimic user behaviour and escape some detection methods. Example: If there is a 30 second ad, -0.1 is given as the skipTo parameter, the video will be instantly skipped to 29.900 (0.1 seconds before the 30 second mark). If positive 10 seconds is given as the skipTo parameter, video will be skipped to 10 seconds, 20 seconds and to 30 seconds every time there is a tick of the snippet (happens at every page mutation). If 0 is given as the skipTo parameter, video will be instantly skipped to the end (30 second mark). Unit is in seconds. -0.1 -skip-to:10
-max-attempts If the video is not fully loaded by the time the xpath condition is met; there is a retry mechanism in the snippet. The snippet will try to skip the video once every retryMs interval. maxAttempts parameter will determine the maximum number of attempts the snippet should do before giving up. This parameter doesn't need to be changed for most of the cases but might be useful for some circumvention scenarios. 10 -max-attemps:20
-retry-ms If the video is not fully loaded by the time the xpath condition is met; there is a retry mechanism in the snippet. The snippet will try to skip the video once every retryMs interval. This parameter doesn't need to be changed for most of the cases. Unit is in milliseconds. 10 -retry-ms:100
-wait-until Optional parameter that can be used to delay the running of the snippet until the given state is reached. Accepts: loading, interactive, complete, load or any event name. Pass empty string to disable.-wait-until:“” (Snippet will run immediately) Disabled (snippet runs immediately) -wait-until:load
-run-once Used to disable the snippet after it has skipped the video once. False -run-once:true
-stop-on-video-end Used to pause the snippet when the video is already near its end. Video is considered near its end when the difference between the video duration and the current time is less than 0.5 seconds. False -stop-on-video-end:true
-start-from Delays running of the snippet until the given time. Unit is in ms. 0 -start-from:1000
-mute-video-when-skipping Mutes the video when the skipping logic is running. True -mute-video-when-skipping:false

strip-fetch-query-parameter

Since: Adblock Plus 3.5.1

Strips a query string parameter from fetch() calls.

Name Description Mandatory
name The name of the parameter. yes
urlPattern An optional pattern that the URL must match. If the string begins and ends with a slash (/), the text in between is treated as a regular expression. no

prevent-window-open

Since: Adblock Plus 4.43.1

Prevents window.open calls whose arguments match a pattern, optionally returning a decoy pop-up handle so the page cannot detect the block by inspecting the returned window. Non-matching calls pass through to the native window.open. The wrapper preserves the native property descriptor and toString() output.

Name Description Mandatory Default value
pattern Matched against all window.open arguments joined with spaces. /.../ is a regex, /.../i a case-insensitive regex, anything else an escaped literal. A leading ! inverts the match. Empty matches every call. no ''
delay Milliseconds. If omitted, prevented calls return null. If set, a decoy handle is returned and removed after this many milliseconds. It is the presence of the parameter, not its value, that switches the decoy on. no ''
decoy iframe loads the URL in a hidden 1x1 iframe; obj uses an <object> instead; blank opens a real pop-up at about:blank. Only relevant when delay is set. no iframe

replace-argument

Since: Adblock Plus 4.42.0

Wraps a native method and rewrites one of its call arguments before the method runs. On each call the first rule that actually changes the argument wins, and the original method is always invoked.

Name Description Mandatory Default value
methodPath Dotted path to the method to wrap, resolved from the page global, e.g. adConfig.setEnabled. yes n.a.
argPosition Zero-based index of the argument to rewrite. Calls passing fewer arguments are skipped. yes n.a.
pattern Regex or literal text matched against the stringified argument. An empty string replaces the whole argument instead, with a typed value from the same list as override-property-read. no ''
replacement The replacement text, or the value token in whole-value mode. no ''
stackNeedle Comma-separated strings or regex which must be present in the callstack for the rule to apply. no ''

replace-fetch-request

Since: Adblock Plus 4.43.2

Replaces the request body of fetch() calls before they are sent, if the body matches a given string. The fetch counterpart of replace-xhr-request. Only string bodies are rewritten; FormData, Blob, URLSearchParams and ArrayBuffer pass through untouched.

Name Description Mandatory Default value
search String or regex pattern to match in the request body. Every occurrence is replaced. If the value starts with jsonpath(, it is treated as a JSONPath query instead. yes n.a.
replacement The string to replace the matched pattern with. In JSONPath mode it is parsed as JSON, so false becomes the boolean and [] an empty array. no ''
needle Regex to pre-filter on the body content. If specified, the replacement only applies when the needle matches. no null
mode JSONPath operation mode. replace sets the matched property; append adds to the existing value instead. Ignored outside JSONPath mode. no replace

Conditional Hiding Snippets

Snippets that are responsible for hiding page content based on various conditions like matching text, style, machine learning model, etc.

hide-if-canvas-contains

Since: Adblock Plus 4.7

The hide-if-canvas-contains snippet hides a canvas element, or a parent element specified by the selector parameter, if the canvas contains the specified search term in it.

We override the fillText, strokeText, and drawImage canvas methods. When a website uses these functions, it won't use the native functions but instead use our overridden proxies. This allows us to know when a website writes text we are interested in (Sponsored, Advertised etc.) to the <canvas>, or loads an image whose source matches a specified pattern, and hide the ad.

Name Description Mandatory Default Allowed values
search String or regex pattern that will be searched in fillText, strokeText and drawImage yes -
selector The selector identifies the HTML element to hide. This can be the canvas element itself or a parent of the canvas. Defaults to the <canvas> element if not provided. no canvas
clearRectBehavior Controls how the snippet handles canvas clearing (clearRect) and whether previously accumulated text should be forgotten. See explanation below. no ““ (empty string) always / never / ““
mode What the search pattern is matched against. In data mode it is matched against canvas.toDataURL(), which is base64-encoded PNG pixel data rather than readable text, so you match a byte signature. Use it when the label leaves nothing in the text buffer or image source. no ““ (empty string) data / ““

clearRectBehavior

Sites often clear their canvas before drawing new content, using clearRect. This parameter controls whether that resets the text accumulated so far.

Value Behaviour
Omitted or empty The accumulated text is reset only when the entire canvas is cleared, since a full clear usually means a new render is starting. Partial clears do not reset it. Start here unless you observe problems.
always The text is forgotten whenever any part of the canvas is cleared. Use this if the snippet matches content that should not be hidden, which happens when a site clears small areas between draws and unrelated fragments combine into a false match.
never The text is never reset. Use this if the snippet misses an ad that should match, which happens when the label is drawn in several passes with full clears in between.

When more than one filter targets the same canvas, these values are aggregated rather than applied independently: if any active filter uses always, text is forgotten on every clearRect, and text is only never forgotten when all of them specify never.

hide-if-contains

Since: Adblock Plus 3.3

Hides any HTML element or one of its ancestors matching a CSS selector if the text content of the element contains a given string.

Name Description Mandatory
search The string to look for in HTML elements. If the string begins and ends with a slash (/), the text in between is treated as a regular expression. yes
selector The CSS selector that an HTML element must match for it to be hidden. yes
searchSelector The CSS selector that an HTML element containing the given string must match. Defaults to the value of the selector argument. no

hide-if-contains-image

Since: Adblock Plus 3.4.2

Hides any HTML element or one of its ancestors matching a CSS selector if the background image of the element matches a given pattern.

Name Description Mandatory
search The pattern to look for in the background images of HTML elements. This must be the hexadecimal representation of the image data for which to look. If the string begins and ends with a slash (/), the text in between is treated as a regular expression. yes
selector The CSS selector that an HTML elemen

(本文超出站点单文档体积上限,已截断)