Static filter syntax·续2
These are valid methods:
-
connect -
delete -
get -
head -
options -
patch -
post -
put
As per DNR's own documentation:
- https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RequestMethod
Example:
||google.com^$method=post|get
||example.com^$method=~get
The logger shows the method used for every network request. It's possible to filter the logger output for most-common methods: get, head, post.
permissions
New in 1.50.1b16.
Permissions Policy provides mechanisms to explicitly declare what functionality can and cannot be used on a website. It is similar to Content Security Policy but controls features instead of security behavior.
Examples of what you can do with Permissions Policy:
-
Change the default behavior of autoplay on mobile and third-party videos.
-
Restrict a site from using sensitive devices like the camera, microphone, or speakers.
-
Allow iframes to use the Fullscreen API.
Related discussion:
- https://github.com/uBlockOrigin/uBlock-issues/discussions/2714
Reference:
-
https://adguard.com/kb/general/ad-filtering/create-own-filters/#permissions-modifier
-
https://docs.w3cub.com/http/headers/feature-policy#directives
-
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy
Example:
||example.com^$permissions=browsing-topics=()
Difference with AdGuard's syntax: use | to separate permissions policy directives instead of \, -- uBO will replace instances of | with ,:
*$permissions=oversized-images=()|unsized-media=()
However, it's best to not combine permissions policy to not break exception filters for either one of them.
When no type (e.g. $doc) is given, uBO will use $document,subdocument internally when the permissions option is used (same as with csp).
ping
Blocks requests send by the ping attribute on links and Navigator.sendBeacon().
popunder
To block "popunders" windows/tabs where the original page redirects to an advertisement and the desired content loads in the newly created one. To be used in the same manner as the popup filter option, except that it will block popunders.
specifichide
Alias: shide.
New in uBO 1.23.0.
When used in an exception filter, it will turn off specific cosmetic filtering on matching pages.
Specific cosmetic filters apply only to pages in domains specified in the filter - example.com##.ad-class.
strict1p
<sup>Framework compatibility: MV2-only</sup>
New in 1.32.0.
Strict first-party request.
The classic option 1p can "weakly" match partyness. For example, a network request qualifies as 1st-party to its context if both the context and the request share the same base domain.
This new strict1p option can check for strict partyness. For example, a network request qualifies as 1st-party if both the context and the request share the same hostname.
For example:
| Context | Request | 1p | strict1p |
| --- | --- | --- | --- |
| www.example.org | www.example.org | yes | yes |
| www.example.org | subdomain.example.org | yes | no |
| www.example.org | www.example.com | no | no |
strict3p
<sup>Framework compatibility: MV2-only</sup>
New in 1.32.0.
Strict third-party requests.
The classic option 3p can "weakly" match partyness. For example, a network request qualifies as 3rd-party to its context only if the context and the request base domains are different.
This new strict3p option can check for strict partyness. For example, a network request qualifies as 3rd-party as soon as the context and the request hostnames are different.
For example:
| Context | Request | 3p | strict3p |
| --- | --- | --- | --- |
| www.example.org | www.example.org | no | no |
| www.example.org | subdomain.example.org | no | yes |
| www.example.org | www.example.com | yes | yes |
to
New in 1.46.1b0.
Related issue: uBlockOrigin/uBlock-issues#2412.
The main motivation of this option is to give uBO's static network filtering engine an equivalent of DNR's requestDomains and excludedRequestDomains.
to= is a superset of denyallow= with support for Entity-based syntax and also negated hostname.
For now denyallow= won't be deprecated, which still does not support entity-based syntax and for which negated domains are not allowed.
Examples:
||it^$3p,to=~example.it
*$script,from=beforeitsnews.com,to=google.*|gstatic.com
Starting with 1.46.1b17 support for regex-based values has been added. Example of usage:
*$script,to=/img[a-z]{3,5}\.buzz/
Related discussion: uBlockOrigin/uBlock-issues#2234
Regex-based domain values can be negated just like plain or entity-based values:
*$to=~/regex.../
top
New in 1.70.1b5.
Related issue: uBlockOrigin/uAssets#17807.
Restrict the filter to be applied only when the specified domain(s) match(es) the top context. The top context is typically the URL in the address bar of your browser.
This option also gives uBO's static network filtering engine an equivalent of DNR's topDomains and excludedTopDomains.
Example, disable generic cosmetic filtering in all embedded contexts (direct and indirect) when hostname of the web page matches example.com:
@@*$generichide,top=example.com
xhr
Equivalent to xmlhttprequest option. For convenience.
Modifier filters
csp
This option will inject an additional Content-Security-Policy header to the HTTP network response of the requested web page. This will make Content Security Policy more strict as designed by the specification. It will be applied to document requests only.
This special filter will not block matching resources but only apply HTTP header to pages matching it. Mixing it with other options specifying resource types like image, script or frame (subdocument) cannot happen. It can still be used with 1p (first-party), 3p (third-party) or domain options.
Because of how csp filters get implemented, they allow for some interesting applications. For example, you can block scripts only in some specific path on the page:
||example.com/subpage/*$csp=script-src 'none'
And even block them everywhere except the main page (note end anchor):
||example.com/*$csp=script-src 'none'
@@||example.com^|$csp=script-src 'none'
An exception filter for a specific csp blocking filter must have the same content of the csp option as the blocking filter. However, an exception filter with an empty csp option will disable all csp injections for the matching page:
@@||example.com^$csp
CSP option syntax is unusual compared to other filters. Recommend to be used only by advanced users. It works in "allowlist" mode allowing data to be downloaded only from addresses explicitly specified in this option. However, uBO is adding its own second CSP header, which as per specification will merge into one final policy. It will enforce the most strict rules from both. For example, you can break a web page if the policy sent by the server allows a.com and b.com and your filter adds c.com; no request will be allowed.
Refer to "Content Security Policy (CSP) Quick Reference Guide" or MDN documentation for further syntax help.
See also denyallow
empty
Deprecated, avoid using this option. See deprecation notice from AdGuard.
New in 1.22.0.
Redirects request to empty response.
The filter option empty is converted internally to redirect=empty.
mp4
Deprecated, avoid using this option. See deprecation notice from AdGuard.
New in 1.22.0.
The mp4 filter option will be converted to redirect=noopmp4-1s internally, and the media type is assumed.
redirect
The redirect option means "block and redirect", and causes two filters to become created internally, a block filter and a redirect directive (redirect-rule).
A redirect directive causes a blocked network request to redirect to a local neutered resource version. The neutered resource must use a resource token. You can use empty redirect resources and URL-specific sanitized redirect resources (surrogates). At runtime, filters with unresolvable resource tokens get discarded.
You can use the redirect= filters with other static filter options. You can exclude them by using @@, they can be badfilter-ed, and their priority can increase with the important option.
Since multiple redirect directives can apply to a single network request, this introduces the concept of redirect priority.
By default, redirect directives have an implicit priority of 0. Filter authors can declare explicitness by appending :[integer] (negative values are also supported) to the redirect= option token. For example:
||example.com/*.js$1p,script,redirect=noopjs:100
The priority dictates which redirect token out of many will ultimately become used. Cases of multiple redirect= directives applying to a single blocked network request are unlikely. All of these directives get reported in the logger. The effective one gets stated as the last one before redirection entry. Use explicit redirect priority only when a case of redirect ambiguity needs solving.
To disable a redirection, you can use an exception filter for the redirect directive (example for the filter above):
@@||example.com/*.js$1p,script,redirect-rule=noopjs
The filter above does not affect blocking filters, just matching redirect directives. You can broadly disable all redirect directives as follow:
@@||example.com/*.js$1p,script,redirect-rule
<details><summary>Before 1.32.0</summary>
Starting with 1.31.0, the redirect= option no longer is afflicted by static network filtering syntax quirks listed below.
-
Must specify resource type.
-
Special, reserved token
nonemust be used to disable specific redirect filters. -
Negated domains in the
domain=option are not supported because of syntax ambiguity - #310. -
Redirections applied to all destinations (starting with
*) cannot be narrowed byfirst-partyor~third-partyoption #3590. -
Disable redirection by specifying
noneas the redirect. (Broken in 1.31.0, fixed in 1.31.3b4) -
Filters with unresolvable resource tokens at runtime will cause redirection to fail. (Changed in 1.31.1b8)
</details>
Available since 1.4.0.
redirect-rule
<sup>Framework compatibility: MV2-only</sup>
Allows creating standalone redirect directives, without an implicit blocking filter.
For example, consider the following filter:
||example.com/ads.js$script,redirect=noop.js
The above filter will result in a block filter ||example.com/ads.js$script and a matching redirect directive. Now consider the following filter:
||example.com/ads.js$script,redirect-rule=noop.js
The above filter will only cause a redirect directive to be created, not a block filter. Standalone redirect directives are helpful when blocking a resource is optional, but still want it to redirect should it ever become blocked by whatever means, whether through a separate block filter, a dynamic filtering rule, etc.
Available since 1.22.0.
removeparam
<sup>Framework compatibility: MV2: full, MV3: partial</sup>
New in 1.32.0.
To remove query parameters from the URL of network requests -- see also AG's removeparam's documentation. For historical reasons, queryprune is an alias of removeparam (avoid using queryprune as it is deprecated and support will get removed eventually).
