Přejít k hlavnímu obsahu

Jak vytvářet vlastní filtry reklam

informace

V tomto článku vysvětlíme, jak napsat vlastní pravidla filtrování pro použití v produktech AdGuardu. Chcete-li otestovat svá pravidla, stáhněte si aplikaci AdGuard

Filtr je sada pravidel filtrování aplikovaných na konkrétní obsah, například bannery nebo vyskakovací okna. AdGuard má seznam standardních filtrů vytvořených naším týmem. Neustále je vylepšujeme, aktualizujeme a snažíme se vyhovět potřebám většiny našich uživatelů.

AdGuard zároveň umožňuje vytvářet vlastní filtry pomocí stejných typů pravidel, které máme v našich filtrech.

K popisu syntaxe našich pravidel filtrování používáme Augmented BNF for Syntax Specifications, ale ne vždy se touto specifikací striktně řídíme.

informace

Původně byla syntaxe AdGuardu založena na syntaxi pravidel Adblock Plus. Později jsme ji rozšířili o nové typy pravidel pro lepší filtrování reklam. Některé části tohoto článku o pravidlech společných pro AdGuard i ABP byly převzaty z příručka Adblock Plus o tom, jak psát filtry.

Komentáře

Každý řádek začínající vykřičníkem je komentář. V seznamu pravidel je zobrazen šedou barvou. AdGuard bude tento řádek ignorovat, takže můžete napsat cokoli chcete. Komentáře se obvykle umísťují nad pravidla a slouží k popisu toho, co pravidlo dělá.

Např:

! Toto je komentář. Pod tímto řádkem se nachází skutečné pravidlo filtrování.
||example.org^

Příklady

Blokování podle názvu domény

Blocking by domain name

Toto pravidlo blokuje:

  • http://example.org/ad1.gif
  • http://subdomain.example.org/ad1.gif
  • https://ads.example.org:8000/

Toto pravidlo neblokuje:

  • http://ads.example.org.us/ad1.gif
  • http://example.com/redirect/http://ads.example.org/

Ve výchozím nastavení tato pravidla pro žádosti o dokumenty nefungují. To znamená, že pravidlo ||example.org^ zablokuje požadavek na example.org při pokusu o přechod na tuto doménu z jiné webové stránky, ale pokud do adresního řádku zadáte example.org a pokusíte se na doménu přejít, webová stránka se otevře. Chcete-li zablokovat žádost o dokument, budete muset použít pravidlo s modifikátorem $document: ||example.org^$document.

Blokování přesné adresy

Blocking exact address

Toto pravidlo blokuje:

  • http://example.org/

Toto pravidlo neblokuje:

  • https://example.org/banner/img

Modifikátory základních pravidel

Pravidla filtrování podporují řadu modifikátorů, které umožňují doladit chování pravidla. Zde je příklad pravidla s několika jednoduchými modifikátory.

Modifikátory základních pravidel

Toto pravidlo blokuje:

  • http://example.org/script.js, pokud je tento skript načten z example.com.

Toto pravidlo neblokuje:

  • https://example.org/script.js, pokud je tento skript načten z example.org.
  • https://example.org/banner.png, protože se nejedná o skript.

Odblokování adresy

Odblokování adresy

Toto pravidlo odblokuje:

  • http://example.org/banner.png, i když pro tuto adresu existuje pravidlo blokování.

Pravidla blokování s modifikátorem $important mohou přepsat výjimky.

Odblokování celé webové stránky

Odblokování celé webové stránky

Toto pravidlo odblokuje

  • Zakáže všechna kosmetická pravidla na example.com.
  • Odblokuje všechny požadavky odeslané z této webové stránky, i když existují pravidla blokování odpovídající těmto požadavkům.

Kosmetické pravidlo

Cosmetic rule

Kosmetická pravidla jsou založena na použití speciálního jazyka CSS, kterému rozumí každý prohlížeč. V podstatě přidává na webové stránky nový styl CSS, jehož účelem je skrýt určité prvky. Více o CSS obecně se můžete dozvědět zde.

AdGuard rozšiřuje CSS a umožňuje tak vývojářům filtrů řešit mnohem složitější případy. Abyste však mohli tato rozšířená pravidla používat, musíte ovládat běžný jazyk CSS.

Oblíbené selektory CSS

NázevSelektor CSSPopis
ID selector#bannersShoduje se se všemi prvky s atributem id rovným banners.
ID selector
Class selector.bannersShoduje se se všemi prvky s atributem class obsahujícím banners.
Class selector
Attribute selectordiv[class="banners"]Shoduje se se všemi prvky div s atributem class přesně rovným k banners.
Attribute selector
Attribute substring selectordiv[class^="advert1"]Shoduje se se všemi prvky div s atributem class začínajícím na řetězec advert1.
Attribute substring selector
Attribute substring selectordiv[class$="banners_ads"]Shoduje se se všemi prvky div s atributem class končícím na řetězec banners_ads.
Attribute substring selector
Attribute substring selectora[href^="http://example.com/"]Shoduje se se všemi odkazy načtenými z domény http://example.com/.
Attribute substring selector
Attribute selectora[href="http://example.com/"]Shoduje se se všemi odkazy exactly adresy http://example.com/.
Attribute selector

Omezení a restrikce

Důvěryhodné filtry

Některá pravidla lze použít pouze v důvěryhodných filtrech. Tato kategorie zahrnuje:

Blokátor obsahu AdGuard

Blokátor obsahu AdGuard je rozšíření pro prohlížeče Samsung a Yandex, které lze nainstalovat z Google Play. Nesmí se zaměňovat s plně funkčním nástrojem AdGuard pro Android, který lze stáhnout pouze z našich stránek. Bohužel, funkce Blokátoru obsahu AdGuard jsou omezeny tím, co prohlížeče umožňují a podporují pouze starou syntaxi filtrů Adblock Plus:

  • Základní pravidla blokování s následujícími modifikátory: $domain, $third-party, modifikátory typu obsahu.
  • Základní pravidla výjimek s následujícími modifikátory: $document, $elemhide.
  • Základní pravidla pro skrývání prvků bez rozšířené podpory CSS.

Vzhledem k výše uvedeným omezením nebude Blokátor obsahu AdGuard uveden v poznámkách ke kompatibilitě.

SafariConverterLib

Safari Converter se snaží co nejvíce podporovat syntaxi pravidel filtrování AdGuard, ale stále existují omezení a nedostatky, které je těžké překonat.

Základní (síťová) pravidla

Safari Converter podporuje podstatnou podmnožinu základních pravidel a určitě podporuje nejdůležitější typy těchto pravidel.

Supported with limitations
  • Pravidla regulárních výrazů jsou omezena na podmnožinu regex podporovanou prohlížečem Safari.

  • $domain - domain modifier is supported with several limitations:

    • Není možné míchat povolené a zakázané domény (například $domain=example.org|~sub.example.org). Dejte prosím pozitivní hodnocení žádosti o funkci pro WebKit, aby toto omezení zrušil.
    • "Libovolná TLD" (tj. domain.*) není plně podporována. V současné implementaci konvertor pouze nahrazuje .* 100 nejoblíbenějšími TLD. Tato implementace bude v budoucnu vylepšena.
    • Použití regulárních výrazů v $domain není podporováno, ale i to bude v budoucnu vylepšeno.
  • $denyallow - tento modifikátor je podporován převodem pravidla $denyallow na sadu pravidel (jedno pravidlo blokování + několik pravidel pro odblokování).

    Vzhledem k tomuto omezení $denyallow je povoleno pouze v případě, že pravidlo má také modifikátor $domain.

    • Generické pravidlo *$denyallow=x.com,image,domain=a.com bude převedeno na:

      *$image,domain=a.com
      @@||x.com$image,domain=a.com
    • Pravidlo /banner.png$image,denyallow=test1.com|test2.com,domain=example.org bude převedeno na:

      /banner.png$image,domain=example.org
      @@||test1.com/banner.png$image,domain=example.org
      @@||test1.com/*/banner.png$image,domain=example.org
      @@||test2.com/banner.png$image,domain=example.org
      @@||test2.com/*/banner.png$image,domain=example.org
    • Pravidlo bez $domainnení podporováno: $denyallow=a.com|b.com.

  • $popup - jsou podporována pravidla vyskakovacích oken, ale jsou v podstatě stejná jako pravidla pro $document-pravidla blokování a nepokusí se kartu zavřít.

  • Pravidla výjimek(@@) zakazují kosmetické filtrování odpovídajících domén.

    Pravidla výjimek v Safari se spoléhají na typ pravidla ignore-previous-rules, takže aby to fungovalo, musíme pravidla seřadit v určitém pořadí. Pravidla výjimek bez modifikátorů jsou umístěna na konci seznamu a proto znemožňují nejen blokování URL, ale i kosmetická pravidla.

    Toto omezení může být zrušeno, pokud bude implementována položka #70.

  • $urlblock, $genericblock je v podstatě stejné jako $document, tj. zakáže všechny druhy filtrování webových stránek.

    Tato omezení mohou být zrušena, až budou zavedeny položky #69 a #71.

  • $content nemá v případě Safari smysl, protože pravidla filtrování HTML nejsou podporována, takže je zde pouze pro účely kompatibility. Pravidla s $content jsou omezena na typ zdroje document.

  • $specifichide je implementováno prohledáním existujících pravidel pro skrývání prvků a odstraněním cílové domény z jejich řady if-domain.

    • $specifichide pravidlo MUSÍ být zaměřeno na doménu, tj. musí vypadat takto: ||example.org^$specifichide. Pravidla s konkrétnějšími vzory budou vyřazena, tj. ||example.org/path$specifichide nebude podporováno.
    • $specifichide se vztahuje pouze na pravidla, která jsou zaměřena na stejnou doménu jako samotné pravidlo, subdomény jsou ignorovány. Tj. pravidlo @@||example.org^$specifichide zakáže example.org##.banner, ale bude ignorovat sub.example.org##.banner. Toto omezení může být zrušeno, pokud bude implementována položka #72.
  • Modifikátory urlblock, genericblock, generichide, elemhide, specifichide a jsinject lze v pravidle použít pouze jako jeden modifikátor. Toto omezení může být v budoucnu zrušeno: #73.

  • $websocket (plně podporováno od Safari 15).

  • $ping (plně podporováno od Safari 14).

Nepodporováno
  • $app
  • $header
  • $method
  • $strict-first-party (bude podporováno v budoucnu: #64)
  • $strict-third-party (bude podporováno v budoucnu: #65)
  • $to (bude podporováno v budoucnu: #60)
  • $extension
  • $stealth
  • $cookie (bude částečně podporováno v budoucnu: #54)
  • $csp
  • $hls
  • $inline-script
  • $inline-font
  • $jsonprune
  • $xmlprune
  • $network
  • $permissions
  • $redirect
  • $redirect-rule
  • $referrerpolicy
  • $removeheader
  • $removeparam
  • $replace
  • $urltransform

Kosmetická pravidla

Safari Converter podporuje většinu kosmetických pravidel ačkoli jsou nativně podporována pouze pravidla skrývání prvků se základními selektory CSS prostřednictvím blokování obsahu v Safari, vše ostatní je třeba interpretovat dalším rozšířením.

Omezení kosmetických pravidel

Pravidla script/scriptlet

Safari Converter plně podporuje pravidla script a pravidla scriplet. Tato pravidla však lze vykládat pouze pomocí samostatného rozšíření.

:::varování

Pro pravidla scriplet je velmi důležité spustit je co nejdříve po načtení stránky. Důvodem je to, že je důležité, aby se spustil dříve než skripty stránky. V prohlížeči Safari bohužel vždy dochází k mírnému zpoždění, které může snížit kvalitu blokování.

:::

HTML pravidla filtrování

Pravidla filtrování HTML nejsou, a v budoucnu nebudou podporována. Safari bohužel neposkytuje potřebné technické možnosti pro jejich implementaci.

Základní pravidla

Nejjednoduššími pravidly jsou tzv. základní pravidla. Slouží k blokování požadavků na konkrétní adresy URL. Nebo je odblokují, pokud je na začátku pravidla speciální znak "@@". Základní princip tohoto typu pravidel je poměrně jednoduchý: je třeba zadat adresu a další parametry, které omezují nebo rozšiřují rozsah pravidla.

Dílčí požadavky

Základní pravidla pro blokování požadavků se vztahují pouze na dílčí požadavky. To znamená, že nebudou blokovat načítání stránky, pokud není výslovně zadána pomocí modifikátoru $document.

Stav odpovědi

Prohlížeč rozpozná zablokovaný požadavek jako dokončený s chybou.

Délka pravidla

Pravidla kratší než 4 znaky jsou považována za nesprávná a budou ignorována.

Syntaxe základních pravidel

      rule = ["@@"] pattern [ "$" modifiers ]
modifiers = [modifier0, modifier1[, ...[, modifierN]]]
  • pattern — maska adresy. Každá adresa URL požadavku je přiřazena k této masce. V šabloně můžete také použít speciální znaky popsané níže. Vezměte na vědomí, že AdGuard zkracuje adresy URL na délku 4096 znaků, aby urychlil porovnávání a předešel problémům s nesmyslně dlouhými adresami URL.
  • @@ — znak, který se používá v pravidlech výjimek. Chcete-li filtrování požadavku vypnout, začněte pravidlo touto značkou.
  • modifiers — parametry, které "objasňují" základní pravidlo. Některé z nich omezují rozsah pravidel a některé mohou zcela změnit jejich fungování.

Speciální znaky

  • * — zástupný znak. Používá se k reprezentaci libovolné sady znaků. Může to být také prázdný řetězec nebo řetězec libovolné délky.
  • || — indikace o použití pravidla na zadanou doménu a její subdomény. S tímto znakem nemusíte v masce adresy zadávat konkrétní protokol a subdoménu. Tj., že || znamená http://*., https://*., ws://*., wss://*. najednou.
  • ^ — oddělovací znak. Oddělovací znak je libovolný znak, mimo písmeno, číslice nebo jeden z následujících znaků: _ - . %. V tomto příkladu jsou oddělovací znaky zobrazeny tučně: http://example.com/?t=1&t2=t3. Konec adresy je také akceptován jako oddělovací znak.
  • | — ukazatel na začátku nebo konci adresy. Hodnota závisí na umístění znaku v masce. Např. pravidlo swf| odpovídá http://example.com/annoyingflash.swf, ale neodpovídá http://example.com/swf/index.html. |http://example.org odpovídá http://example.org, ale ne http://domain.com?url=http://example.org.
poznámka

|, ||, ^ lze použít pouze u pravidel se vzorem URL. Např. ||example.com##.advert je nesprávný a bude blokátorem ignorován.

Vizuální znázornění

Doporučujeme také seznámit se s přehledem filtrů Adblock Plus, abyste lépe pochopili, jak taková pravidla vytvářet.

Podpora regulárních výrazů

Pokud chcete ještě větší flexibilitu při vytváření pravidel, můžete použít regulární výrazy namísto výchozí zjednodušené masky se speciálními znaky.

Výkon

Pravidla s regulárními výrazy pracují pomaleji, proto se jim doporučuje vyhnout nebo omezit jejich rozsah na určité domény.

Pokud chcete, aby blokátor určil regulární výraz, musí pattern vypadat takto:

pattern = "/" regexp "/"

Např. pravidlo /banner\d+/$third-party použije regulární výraz banner\d+ na všechny požadavky třetích stran. Pravidlo výjimky s regulárním výrazem vypadá takto: @@/banner\d+/.

Kompatibilita

AdGuard pro Safari a AdGuard pro iOS plně nepodporují regulární výrazy kvůli omezení API pro blokování obsahu (hledejte sekci "Formát regulárního výrazu").

Podpora zástupných znaků pro TLD (domény nejvyšší úrovně)

Zástupné znaky jsou podporovány pro TLD domén ve vzorech kosmetických, filtrování HTML a pravidel JavaScript.

V případě kosmetických pravidel, např. example.*##.banner, je díky znaku .*, tj. example.com, sub.example.net, example.co.uk, atd. přiřazeno více domén.

Pro základní pravidla platí popsaná logika pouze pro domény uvedené v $domain modifikátoru, např. ||*/banners/*$image,domain=example.*.

Kompatibilita

V AdGuardu pro Windows, Mac, Android a v pravidlech rozšíření prohlížeče AdGuard se zástupným znakem .*, odpovídá jakékoli veřejné příponě (nebo eTLD). Pro AdGuard pro Safari a iOS je však seznam podporovaných domén nejvyšší úrovně omezen kvůli omezením v Safari.

Pravidla se zástupným znakem pro TLD nejsou podporována Blokátorem obsahu AdGuard.

Příklady základních pravidel

  • ||example.com/ads/* — jednoduché pravidlo, které odpovídá adresám typu http://example.com/ads/banner.jpg a dokonce i http://subdomain.example.com/ads/otherbanner.jpg.

  • ||example.org^$third-party — toto pravidlo blokuje požadavky třetích stran na example.org a jejím subdoménám.

  • @@||example.com$document — obecné pravidlo výjimky. Zcela vypne filtrování pro example.com a všechny subdomény. V pravidlech pro výjimky lze použít řadu modifikátorů. Pro více podrobností klikněte na odkaz níže.

Modifikátory základních pravidel

poznámka

Funkce popsané v této části jsou určeny pro zkušené uživatele. Rozšiřují možnosti "základních pravidel", ale abyste je mohli používat, musíte mít základní znalosti o fungování prohlížeče.

Chování "základního pravidla" můžete změnit pomocí dalších modifikátorů. Modifikátory by měly být umístěny na konci pravidla za znakem $ a odděleny čárkami.

Příklad:

||domain.com^$popup,third-party

Základní modifikátory

Následující modifikátory jsou nejjednodušší a nejčastěji používané. V podstatě jen omezují rozsah použití pravidel.

Modifikátor \ ProduktyAplikace CoreLibsAdGuard pro ChromiumAdGuard pro Chrome MV3AdGuard pro FirefoxAdGuard pro iOSAdGuard pro SafariBlokátor obsahu AdGuard
$app
$denyallow
$domain*[1]*[1]*[1]
$header*[2]*[2]
$important
$match-case
$method
$popup*[3]*[3]*[3]*[3]
$strict-first-party
$strict-third-party
$third-party
$to
poznámka
  • ✅ — plně podporováno
  • ✅ * — podporováno, ale spolehlivost se může lišit nebo se mohou vyskytnout omezení; více informací naleznete v popisu modifikátoru
  • ❌ — nepodporováno

$app

Tento modifikátor umožňuje zúžit pokrytí pravidla na konkrétní aplikaci (nebo seznam aplikací). V systémech Windows a Mac to nemusí být příliš důležité, ale v mobilních zařízeních, kde některá pravidla filtrování musí být specifická pro konkrétní aplikaci, je to velmi důležité.

  • Android — použijte název balíčku aplikace, např. org.example.app.
  • Windows — použijte název procesu, např. chrome.exe.
  • Mac — použijte ID svazku nebo název procesu, např. com.google.Chrome.

V případě počítače Mac můžete ID svazku nebo název procesu aplikace zjistit zobrazením příslušných podrobností o požadavku v záznamu filtrování.

Příklady

  • ||baddomain.com^$app=org.example.app — pravidlo pro blokování požadavků, které odpovídají zadané masce a jsou odeslány z Android aplikace org.example.app.
  • ||baddomain.com^$app=org.example.app1|org.example.app2 — stejné pravidlo, ale funguje jak pro org.example.app1, tak i pro org.example.app2.

Pokud chcete, aby se pravidlo nevztahovalo na určité aplikace, začněte název aplikace znakem ~.

  • ||baddomain.com^$app=~org.example.app — pravidlo pro blokování požadavků, které odpovídají zadané masce a jsou odeslány z jakékoli aplikace kromě org.example.app.
  • ||baddomain.com^$app=~org.example.app1|~org.example.app2 — stejně jako výše, ale nyní jsou vyloučeny dvě aplikace: org.example.app1 a org.example.app2.
Omezení

Aplikace v hodnotě modifikátoru nemohou mít zástupný znak, např. $app=com.*.music. Pravidla s takovým modifikátorem jsou považována za neplatná.

Kompatibilita
  • Pouze AdGuard pro Windows, Mac a Android jsou technicky schopné používat pravidla s modifikátorem $app.
  • On Windows the process name is case-insensitive starting with AdGuard for Windows with CoreLibs v1.12 or later.

$denyallow

Modifikátor $denyallow umožňuje vyhnout se vytváření dalších pravidel, pokud je potřeba zakázat určité pravidlo pro konkrétní domény. $denyallow odpovídá pouze cílovým doménám, nikoli doménám odkazujícím.

Přidání tohoto modifikátoru k pravidlu je ekvivalentní vyloučení domén podle shodného vzoru pravidla nebo přidání odpovídajících pravidel výjimek. Chcete-li do jednoho pravidla přidat více domén, použijte jako oddělovací znak |.

Příklady

Toto pravidlo:

*$script,domain=a.com|b.com,denyallow=x.com|y.com

odpovídá tomuto:

/^(?!.*(x.com|y.com)).*$/$script,domain=a.com|b.com

nebo kombinaci těchto tří:

*$script,domain=a.com|b.com
@@||x.com$script,domain=a.com|b.com
@@||y.com$script,domain=a.com|b.com
Omezení
  • Vzor shody pravidla se nemůže zaměřit na žádné konkrétní domény, např. nemůže začínat ||.
  • Domény v hodnotě modifikátoru nemohou být negovány, např. $denyallow=~x.com, nebo mít zástupný znak TLD, např. $denyallow=x.*, nebo být regulárním výrazem, např. ;$denyallow=/\.(com\|org)/.
  • $denyallow nelze použít společně s $to. Lze ji vyjádřit pomocí invertovaného $to: $denyallow=a.com|b.com, což je je ekvivalent k $to=~a.com|~b.com.

Pravidla, která tato omezení porušují, jsou považována za neplatná.

Kompatibilita

Pravidla s modifikátorem $denyallow nejsou AdGuardem pro iOS, Safari a Blokátorem obsahu AdGuard podporována.

$domain

$domain omezuje rozsah pravidla na požadavky ze zadaných domén a jejich subdomén (jak je uvedeno v záhlaví Referer HTTP).

Syntaxe

Modifikátor je seznam jednoho nebo více výrazů oddělených symbolem |, z nichž každý je porovnáván s doménou určitým způsobem v závislosti na svém typu (viz níže).

domains = ["~"] entry_0 ["|" ["~"] entry_1 ["|" ["~"]entry_2 ["|" ... ["|" ["~"]entry_N]]]]
entry_i = ( regular_domain / any_tld_domain / regexp )
  • regular_domain — běžný název domény (domain.com). Odpovídá zadané doméně a jejím subdoménám. Shoduje se lexikograficky.
  • any_tld_domain — název domény zakončený zástupným znakem jako veřejná přípona, např. pro example.* je to co.uk v example.co.uk. Odpovídá zadané doméně a jejím subdoménám s libovolnou veřejnou příponou. Shoduje se lexikograficky.
  • regexp — regulární výraz, který začíná a končí znakem /. Vzor funguje stejně jako v základních pravidlech URL, ale znaky /, $, , a | musí být uvozeny pomocí \.
informace

Pravidla s modifikátorem $domain jako regular_domain jsou podporována všemi AdGuard produkty.

Příklady

Jen $domain:

  • ||baddomain.com^$domain=example.org blokuje požadavky, které odpovídají zadané masce a jsou odeslány z domény example.org nebo jejích subdomén.
  • ||baddomain.com^$domain=example.org|example.com — stejné pravidlo, ale funguje jak pro example.org, tak i pro example.com.

Pokud chcete, aby se pravidlo nevztahovalo na určité domény, začněte název domény znakem ~.

$domain a negace ~:

  • ||baddomain.com^$domain=example.org blokuje požadavky, které odpovídají zadané masce a jsou odeslány z domény example.org nebo jejích subdomén.
  • ||baddomain.com^$domain=example.org|example.com — stejné pravidlo, ale funguje jak pro example.org, tak i pro example.com.
  • ||baddomain.com^$domain=~example.org blokuje požadavky, které odpovídají vzoru a jsou odeslané z jakékoli domény kromě example.org a jejích subdomén.
  • ||baddomain.com^$domain=example.org|~foo.example.org blokuje požadavky odeslané z example.org a jích subdomén, kromě subdomény foo.example.org.
  • ||baddomain.com^$domain=/(^\|.+\.)example\.(com\|org)\$/ blokuje požadavky odeslané z example.org a example.com a všech jejích subdomén.
  • ||baddomain.com^$domain=~a.com|~b.*|~/(^\|.+\.)c\.(com\|org)\$/ blokuje požadavky odeslané z a.com, b s libovolnou veřejnou příponou (b.com, b.co.uk, etc.), c.com, c.org, a jejich subdomén.

$domain modifikátor odpovídající cílové doméně:

V některých případech může modifikátor $domain odpovídat nejen doméně odkazovače, ale také cílové doméně. K tomu dojde, pokud jsou splněny všechny následující podmínky:

  1. Požadavek má typ obsahu document
  2. Vzor pravidla neodpovídá žádné konkrétní doméně
  3. Vzor pravidla neobsahuje regulární výrazy
  4. Modifikátor $domain obsahuje pouze domény ve výjimkách, např. $domain=~example.org|~example.com

Následující predikát by měl být splněn, aby bylo možné provést porovnání cílové domény:

1 AND ((2 AND 3) OR 4)

To znamená, že pokud modifikátor $domain obsahuje pouze domény ve výjimkách, pak pravidlo nemusí splňovat druhou a třetí podmínku, aby se cílová doména shodovala s modifikátorem $domain.

Pokud některé z výše uvedených podmínek nejsou splněny, ale pravidlo obsahuje modifikátor $cookie nebo $csp, cílová doména bude přesto přiřazena.

Pokud odkazující doména odpovídá pravidlu s $domain, které výslovně vylučuje doménu odkazujícího serveru, pravidlo se nepoužije, i když cílová doména také odpovídá pravidlu. To má vliv i na pravidla s modifikátory $cookie a $csp.

Příklady

  • *$cookie,domain=example.org|example.com zablokuje soubory cookie pro všechny požadavky do a z domény example.org a example.com.
  • *$document,domain=example.org|example.com zablokuje všechny požadavky do a z domény example.org a example.com.

V následujících příkladech se předpokládá, že požadavky jsou odesílány z adresy http://example.org/page (odkazující adresa), cílová adresa URL je http://targetdomain.com/page.

  • page$domain=example.org bude přiřazena, protože odpovídá doméně odkazu.
  • page$domain=targetdomain.com bude přiřazena, protože odpovídá cílové doméně a splňuje všechny výše uvedené požadavky.
  • ||*page$domain=targetdomain.com nebude přiřazena, protože vzor ||*page odpovídá konkrétním doménám, např. example.page.
  • ||*page$domain=targetdomain.com,cookie bude přiřazena, protože pravidlo obsahuje modifikátor $cookie, přestože vzor ||*page může odpovídat konkrétním doménám.
  • /banner\d+/$domain=targetdomain.com nebude přiřazena, protože obsahuje regulární výraz.
  • page$domain=targetdomain.com|~example.org nebude přiřazena, protože doména odkazu je výslovně vyloučena.
omezení modifikátoru $domain
Omezení

In AdGuard for Chrome MV3, regexp and any_tld_domain entries are not supported.

AdGuard for iOS and AdGuard for Safari support the $domain modifier but have some limitations. For more details, see the SafariConverterLib section.

Kompatibilita

Rules with regular expressions in the $domain modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.11 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.

In AdGuard for Windows, Mac and Android with CoreLibs v1.12 or later the $domain modifier can be alternatively spelled as $from.

$header

The $header modifier allows matching the HTTP response having a specific header with (optionally) a specific value.

Syntax

$header "=" h_name [":" h_value]
h_value = string / regexp

where:

  • h_name — povinný název záhlaví HTTP. Je přizpůsoben případ od případu.
  • h_value — nepovinný výraz odpovídající hodnotě záhlaví HTTP, může to být jeden z následujících výrazů:
    • string — posloupnost znaků. Porovnává se s hodnotou záhlaví lexikograficky;
    • regexp — regulární výraz, který začíná a končí znakem /. Vzor funguje stejně jako v základních pravidlech pro URL adresy, ale znaky /, $ a , musí být uvozeny pomocí \.

The modifier part, ":" h_value, may be omitted. In that case, the modifier matches the header name only.

Příklady

  • ||example.com^$header=set-cookie:foo blokuje požadavky, jejichž odpovědi mají hlavičku Set-Cookie s hodnotou odpovídající foo.
  • ||example.com^$header=set-cookie blokuje požadavky, jejichž odpovědi mají hlavičku Set-Cookie s libovolnou hodnotou.
  • @@||example.com^$header=set-cookie:/foo\, bar\$/ odblokuje požadavky, jejichž odpovědi mají hlavičku Set-Cookie s hodnotou odpovídající regulárnímu výrazu foo, bar$.
  • @@||example.com^$header=set-cookie odblokuje požadavky, jejichž odpovědi mají hlavičku Set-Cookie s libovolnou hodnotou.
omezení modifikátoru $header
Omezení
  1. Modifikátor $header lze použít pouze při příjmu záhlaví. Pokud je tedy požadavek zablokován nebo přesměrován v dřívější fázi, nelze modifikátor použít.

  2. V Rozšíření prohlížeče AdGuard je modifikátor $header kompatibilní poze s $csp, $removeheader (pouze hlavičky odpovědí), $important, $badfilter, $domain, $third-party, $match-case s content-type modifiers jako $script a $stylesheet. Pravidla s jinými modifikátory jsou považována za neplatná a budou vyřazena.

Kompatibilita

Rules with the $header modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.11 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.

$important

The $important modifier applied to a rule increases its priority over rules without the identical modifier. Even over basic exception rules.

Go to rules priorities for more details.

Příklady

! pravidlo blokování zablokuje všechny požadavky navzdory pravidlu výjimky
||example.org^$important
@@||example.org^
! pokud má pravidlo výjimky také modifikátor `$important`, bude mít přednost a žádné požadavky nebudou blokovány
||example.org^$important
@@||example.org^$important

$match-case

This modifier defines a rule which applies only to addresses that match the case. Default rules are case-insensitive.

Příklady

  • */BannerAd.gif$match-case — toto pravidlo zablokuje http://example.com/BannerAd.gif, ale ne http://example.com/bannerad.gif.
Kompatibilita

Rules with the $match-case are supported by AdGuard for iOS and AdGuard for Safari with SafariConverterLib v2.0.43 or later.

All other products already support this modifier.

$method

This modifier limits the rule scope to requests that use the specified set of HTTP methods. Negated methods are allowed. The methods must be specified in all lowercase characters, but are matched case-insensitively. To add multiple methods to one rule, use the vertical bar | as a separator.

Příklady

  • ||evil.com^$method=get|head blokuje pouze požadavky GET a HEAD na doméně evil.com.
  • ||evil.com^$method=~post|~put blokuje všechny požadavky na doméně evil.com kromě POST nebo PUT.
  • @@||evil.com$method=get odblokuje pouze požadavky GET na doméně evil.com.
  • @@||evil.com$method=~post odblokuje jakékoliv požadavky na doméně evil.com kromě POST.
Omezení

Rules with mixed negated and not negated values are considered invalid. So, for example, the rule ||evil.com^$method=get|~head will be ignored.

Kompatibilita

Rules with $method modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.12 or later, and AdGuard Browser Extension for Chrome, Firefox, and Edge with TSUrlFilter v2.1.1 or later.

AdGuard will try to close the browser tab with any address that matches a blocking rule with this modifier. Please note that not all the tabs can be closed.

Příklady

  • ||domain.com^$popup — pokud se pokusíte přejít na http://domain.com/ z libovolné stránky v prohlížeči, nová karta, ve které má být zadaný web otevřen, bude tímto pravidlem zavřena.
Omezení
  1. Modifikátor $popup funguje nejlépe v rozšíření prohlížeče AdGuard pro prohlížeče založené na Chromiu a Firefox.
  2. In AdGuard for Chrome MV3 rules with the $popup modifier would not work, so we disable converting them to declarative rules. We will try to use them only in our TSUrlFilter engine and close new tabs programmatically.
  3. V AdGuardu pro Safari a AdGuardu pro iOS, pravidla $popup stránku jednoduše a okamžitě zablokují.
  4. V AdGuardu pro Windows, Mac, Android a Linux nemusí modifikátor $popup v některých případech detekovat vyskakovací okno a nebude zablokováno. Modifikátor $popup použije typ obsahu document se speciálním příznakem, který je předán blokovací stránce. Samotná blokovací stránka může provést některé kontroly a zavřít okno, pokud se skutečně jedná o vyskakovací okno. V opačném případě by se stránka měla načíst. Lze jej kombinovat s dalšími modifikátory typu požadavku, například $third-party, $strict-third-party, $strict-first-party a $important.
Kompatibilita

Rules with the $popup modifier are not supported by AdGuard Content Blocker.

$strict-first-party

Works the same as the $~third-party modifier, but only treats the request as first-party if the referrer and origin have exactly the same hostname.

Příklady

  • domain.com$strict-first-party' – toto pravidlo platí pouze pro domena.com. Např. požadavek z domain.com na http://domain.com/icon.ico je požadavek vlastní. Požadavek z sub.domain.com na http://domain.com/icon.ico je považován za požadavek třetí strany (na rozdíl od modifikátoru $~third-party).
poznámka

You can use a shorter name (alias) instead of using the full modifier name: $strict1p.

Kompatibilita

Rules with the $strict-first-party modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.16 or later.

$strict-third-party

Works the same as the $third-party modifier but also treats requests from the domain to its subdomains and vice versa as third-party requests.

Příklady

  • ||domain.com^$strict-thirdparty — toto pravidlo bude použito na všechny domény, kromě domain.com. Příklad požadavku třetí strany: http://sub.domain.com/banner.jpg (na rozdíl od modifikátoru $third-party).
poznámka

You can use a shorter name (alias) instead of using the full modifier name: $strict3p.

Kompatibilita

Rules with the $strict-third-party modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.16 or later.

$third-party

A restriction on third-party and custom requests. A third-party request is a request from an external domain. For example, a request to example.org from domain.com is a third-party request.

poznámka

To be considered as such, a third-party request should meet one of the following conditions:

  1. Její odkazující doména není subdoménou cílové domény nebo naopak. Např. požadavek na subdomain.example.org z example.org není požadavek třetí strany
  2. Její záhlaví Sec-Fetch-Site je nastaveno na cross-site

Příklady

$third-party:

  • ||domain.com^$third-party — toto pravidlo bude použito na všechny domény, kromě domain.com a její subdomény. Příklad požadavku třetí strany: http://example.org/banner.jpg.

If there is a $~third-party modifier, the rule is only applied to the requests that are not from third parties. Which means, they have to be sent from the same domain.

$~third-party:

  • ||domain.com$~third-party — toto pravidlo se vztahuje výhradně na domain.com. Příklad požadavku která není podán třetí stranou: http://domain.com/icon.ico.
poznámka

You may use a shorter name (alias) instead of using the full modifier name: $3p.

$to

$to limits the rule scope to requests made to the specified domains and their subdomains. Chcete-li do jednoho pravidla přidat více domén, použijte jako oddělovací znak |.

Příklady

  • /ads$to=evil.com|evil.org zablokuje jakýkoliv požadavek na evil.com nebo evil.org a jejich subdomény s cestou, která odpovídá /ads.
  • /ads$to=~not.evil.com|evil.com zablokuje jakýkoliv požadavek na evil.com a její subdomény s cestou, která odpovídá /ads, kromě požadavků na not.evil.com a její subdomény.
  • /ads$to=~good.com|~good.org zablokuje všechny požadavky s cestou, která odpovídá /ads, kromě požadavků na good.com nebo good.org a jejich subdomény.
Omezení

$denyallow cannot be used together with $to. Lze ji vyjádřit pomocí invertovaného $to: $denyallow=a.com|b.com, což je je ekvivalent k $to=~a.com|~b.com.

Kompatibilita

Rules with the $to modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.12 or later, and AdGuard Browser Extension with TSUrlFilter v2.1.3 or later.

Modifikátory typu obsahu

There is a set of modifiers, which can be used to limit the rule's application area to certain type of content. These modifiers can also be combined to cover, for example, both images and scripts.

Kompatibilita

There is a big difference in how AdGuard determines the content type on different platforms. For AdGuard Browser Extension, content type for every request is provided by the browser. AdGuard for Windows, Mac, and Android use the following method: first, the apps try to determine the type of the request by the Sec-Fetch-Dest request header or by the filename extension. If the request is not blocked at this stage, the type will be determined using the Content-Type header at the beginning of the server response.

Examples of content-type modifiers

  • ||example.org^$image — odpovídá všem obrázkům z example.org.
  • ||example.org^$script,stylesheet — odpovídá všem skriptům a stylům z example.org.
  • ||example.org^$~image,~script,~stylesheet — odpovídá všem požadavkům na example.org kromě obrázků, skriptů a stylů.
Modifikátor \ ProduktyAplikace CoreLibsAdGuard pro ChromiumAdGuard pro Chrome MV3AdGuard pro FirefoxAdGuard pro iOSAdGuard pro SafariBlokátor obsahu AdGuard
$document
$font
$image
$media
$object
$other
$ping*[1]
$script
$stylesheet
$subdocument*[2]
$websocket*[3]*[3]
$xmlhttprequest
$webrtc 🚫
$object-subrequest 🚫
poznámka
  • ✅ — plně podporováno
  • ✅ * — podporováno, ale spolehlivost se může lišit nebo se mohou vyskytnout omezení; více informací naleznete v popisu modifikátoru
  • ❌ — nepodporováno
  • 🚫 — odstraněno a již nepodporováno

$document

The rule corresponds to the main frame document requests, i.e. HTML documents that are loaded in the browser tab. It does not match iframes, there is a $subdocument modifier for these.

By default, AdGuard does not block the requests that are loaded in the browser tab (e.g. "main frame bypass"). The idea is not to prevent pages from loading as the user clearly indicated that they want this page to be loaded. However, if the $document modifier is specified explicitly, AdGuard does not use that logic and prevents the page load. Instead, it responds with a "blocking page".

If this modifier is used with an exclusion rule (@@), it completely disables blocking on corresponding pages. It is equivalent to using $elemhide, $content, $urlblock, $jsinject, $extension modifiers simultaneously.

Příklady

  • @@||example.com^$document zcela zakáže filtrování všech stránek na example.com a všech subdoménách.

  • ||example.com^$document zablokuje požadavek na dokument HTML na example.com pomocí blokační stránky.

  • ||example.com^$document,redirect=noopframe přesměruje požadavek na HTML dokument na example.com na prázdný HTML dokument.

  • ||example.com^$document,removeparam=test odebere parametr dotazu test z požadavku dokumentu HTML na example.com.

  • ||example.com^$document,replace=/test1/test2/ nahradí test1 za test2 v požadavku na dokument HTML na example.com.

poznámka

You may use a shorter name (alias) instead of using the full modifier name: $doc.

$font

The rule corresponds to requests for fonts, e.g. .woff filename extension.

$image

The rule corresponds to images requests.

$media

The rule corresponds to requests for media files — music and video, e.g. .mp4 files.

$object

The rule corresponds to browser plugins resources, e.g. Java or Flash.

Kompatibilita

Rules with $object modifier are not supported by AdGuard for Safari and AdGuard for iOS.

$other

The rule applies to requests for which the type has not been determined or does not match the types listed above.

$ping

The rule corresponds to requests caused by either navigator.sendBeacon() or the ping attribute on links.

omezení modifikátoru $ping
Omezení

AdGuard for Windows, Mac, and Android often cannot accurately detect navigator.sendBeacon(). Using $ping is not recommended in the filter lists that are supposed to be used by CoreLibs-based AdGuard products.

Kompatibilita

Rules with $ping modifier are not supported by AdGuard for Safari and AdGuard for iOS.

$script

The rule corresponds to script requests, e.g. JavaScript, VBScript.

$stylesheet

The rule corresponds to CSS files requests.

poznámka

You may use a shorter name (alias) instead of using the full modifier name: $css.

$subdocument

The rule corresponds to requests for built-in pages — HTML tags frame and iframe.

Příklady

  • ||example.com^$subdocument blokuje integrované požadavky (frame a iframe) na example.com a všechny její subdomény kdekoli.
  • ||example.com^$subdocument,domain=domain.com blokuje integrované požadavky (frame и iframe) na example.com (a její subdomény) z domain.com a všech jejích subdomén.
poznámka

You may use a shorter name (alias) instead of using the full modifier name: $frame.

omezení modifikátoru $subdocument
Omezení

In AdGuard for Windows, Mac, and Android subdocuments are being detected by the Sec-Fetch-Dest header if it is present. Otherwise, some main pages may be treated as subdocuments.

Kompatibilita

Rules with $subdocument modifier are not supported by AdGuard Content Blocker.

$websocket

The rule applies only to WebSocket connections.

omezení modifikátoru $websocket
Omezení

For AdGuard for Safari and AdGuard for iOS, it is supported on devices with macOS Monterey (version 12) and iOS 16 or higher respectively.

Kompatibilita

$websocket modifier is supported in all AdGuard products except AdGuard Content Blocker.

$xmlhttprequest

The rule applies only to ajax requests (requests sent via the JavaScript object XMLHttpRequest).

poznámka

You may use a shorter name (alias) instead of using the full modifier name: $xhr.

Kompatibilita

AdGuard for Windows, Mac, Android when filtering older browsers cannot accurately detect this type and sometimes detects it as $other or $script. They can only reliably detect this content type when filtering modern browsers that support Fetch metadata request headers.

$object-subrequest (odstraněno)

Removal notice

$object-subrequest modifier is removed and is no longer supported. Rules with it are considered as invalid. The rule corresponds to requests by browser plugins (it is usually Flash).

$webrtc (odstraněno)

Removal notice

This modifier is removed and is no longer supported. Rules with it are considered as invalid. If you need to suppress WebRTC, consider using the nowebrtc scriptlet.

The rule applies only to WebRTC connections.

Příklady

  • ||example.com^$webrtc,domain=example.org blokuje připojení webRTC na example.com z example.org.
  • @@*$webrtc,domain=example.org zakáže RTC wrapper pro example.org.

Modifikátory pravidel pro výjimky

Exception rules disable the other basic rules for the addresses to which they correspond. They begin with a @@ mark. All the basic modifiers listed above can be applied to them and they also have a few special modifiers.

Vizuální znázornění

We recommend to get acquainted with the Adblock Plus filter cheatsheet, for better understanding of how exception rules should be made.

Modifikátor \ ProduktyAplikace CoreLibsAdGuard pro ChromiumAdGuard pro Chrome MV3AdGuard pro FirefoxAdGuard pro iOSAdGuard pro SafariBlokátor obsahu AdGuard
$content
$elemhide
$extension
$jsinject*[1]
$stealth
$urlblock*[2]*[2]
$genericblock*[3]*[3]
$generichide
$specifichide
poznámka
  • ✅ — plně podporováno
  • ✅ * — podporováno, ale spolehlivost se může lišit nebo se mohou vyskytnout omezení; více informací naleznete v popisu modifikátoru
  • ❌ — nepodporováno
informace

By default, without specifying additional content type modifiers, exception rule modifiers override other basic rules only for main frame document requests (see $document for more information about main frame document).

Např:

  • Webová stránka example.com obsahuje iframe odkazující na example1.com.
  • Použije se pravidlo #%#//console.log('test').

In this case, the log will appear twice in the console: once for the main frame document and once for iframe.

If you add the @@||example.com^$jsinject rule, the log will appear only once for iframe.

$content

Disables HTML filtering, $hls, $replace, and $jsonprune rules on the pages that match the rule.

Příklady

  • @@||example.com^$content zakáže všechna pravidla pro úpravu obsahu na stránkách example.com a všech jích subdoménách.

$elemhide

Disables any cosmetic rules on the pages matching the rule.

Příklady

  • @@||example.com^$elemhide zakáže všechna kosmetická pravidla na example.com a všech subdoménách.
poznámka

You may use a shorter name (alias) instead of using the full modifier name: $ehide.

$extension

Disables specific userscripts or all userscripts for a given domain.

Syntax

$extension[="userscript_name1"[|"userscript_name2"[|"userscript_name3"[...]]]]

userscript_name(i) stands for a specific userscript name to be disabled by the modifier. The modifier can contain any number of userscript names or none. In the latter case the modifier disables all the userscripts.

Userscript names usually contain spaces or other special characters, which is why you should enclose the name in quotes. Both single (') and double (") ASCII quotes are supported. Multiple userscript names should be separated with a pipe (|). However, if a userscript name is a single word without any special characters, it can be used without quotes.

You can also exclude a userscript by adding a ~ character before it. In this case, the userscript will not be disabled by the modifier.

$extension=~"userscript name"
poznámka

When excluding a userscript, you must place ~ outside the quotes.

If a userscript's name includes quotes ("), commas (,), or pipes (|), they must be escaped with a backslash (\).

$extension="userscript name\, with \"quote\""

Příklady

  • @@||example.com^$extension="AdGuard Assistant" zakáže uživatelský skript AdGuard asistent na example.com.
  • @@||example.com^$extension=MyUserscript zakáže uživatelský skript MyUserscript na example.com.
  • @@||example.com^$extension='AdGuard Assistant'|'AdGuard Popup Blocker' zakáže uživatelské skripty AdGuard asistent a Blokátor vyskakovacích okenAdGuard na example.com.
  • @@||example.com^$extension=~"AdGuard Assistant" zakáže všechny uživatelské skripty na example.com, kromě AdGuard asistenta.
  • @@||example.com^$extension=~"AdGuard Assistant"|~"AdGuard Popup Blocker" zakáže všechny uživatelské skripty na example.com, kromě AdGuard asistenta a Blokátor vyskakovacích oken AdGuard.
  • @@||example.com^$extension žádné uživatelské skripty nebudou fungovat na example.com.
  • @@||example.com^$extension="AdGuard \"Assistant\"" zakáže uživatelský skript AdGuard "Asistant" na example.com.
Kompatibilita
  • Pouze AdGuard pro Windows, Mac a Android jsou technicky schopné používat pravidla s modifikátorem $extension.
  • Rules with $extension modifier with specific userscript name are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.13 or later.

$jsinject

Forbids adding of JavaScript code to the page. You can read about scriptlets and javascript rules further.

Příklady

  • @@||example.com^$jsinject zakáže javasript na example.com a všech subdoménách.
omezení modifikátoru $jsinject
Limitations

Rules with the $jsinject modifier cannot be converted to DNR in AdGuard for Chrome MV3. We only use them in the TSUrlFilter engine to disable some cosmetic rules.

Kompatibilita

The $jsinject modifier is not supported by AdGuard for Chrome MV3 (yet) and AdGuard Content Blocker.

$stealth

Disables the Tracking protection (formerly Stealth Mode) module for all corresponding pages and requests.

Syntax

$stealth [= opt1 [| opt2 [| opt3 [...]]]]

opt(i) stand for certain Tracking protection options disabled by the modifier. The modifier can contain any number of specific options (see below) or none. In the latter case the modifier disables all the Tracking protection features.

The list of the available modifier options:

Příklady

  • @@||example.com^$stealth zakáže Ochranu před sledováním pro požadavky example.com (a subdomény) s výjimkou blokování cookies a skrytí sledovacích parametrů (viz níže).
  • @@||domain.com^$script,stealth,domain=example.com zakáže Ochranu před sledováním pouze pro požadavky skriptů na domain.com (a subdoménách) na example.com a subdoménách.
  • @@||example.com^$stealth=3p-cookie|dpi zakáže blokování cookies třetích stran a opatření pro oklamání DPI pro example.com.
poznámka

Blocking cookies and removing tracking parameters is achieved by using rules with the $cookie, $urltransform and $removeparam modifiers. Exception rules that contain only the $stealth modifier will not do these things. If you want to completely disable all Tracking protection features for a given domain, you must include all three modifiers: @@||example.org^$stealth,removeparam,cookie.

Omezení
  • Možnosti modifikátoru musí být psány malými písmeny, tj. $stealth=DPI budou zamítnuty.
  • Možnosti modifikátoru nelze negovat, tj. $stealth=~3p-cookie bude zamítnuto.
  • Rozšíření prohlížeče AdGuard podporuje pouze možnosti searchqueries, donottrack, referrer, xclientdata, 1p-cookie a 3p-cookie.
Kompatibilita
  • Ochrana před sledováním (dříve Režim utajení) je k dispozici v AdGuardu pro Windows, AdGuardu pro macOS, AdGuardu pro Android a Rozšíření prohlížeče AdGuard pro Firefox a prohlížeče založené na Chromium, kromě AdGuardu pro Chrome Manifest MV3. Všechny ostatní produkty budou ignorovat pravidla s modifikátorem $stealth.
  • Rules with $stealth modifier with specific options are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.10 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.

$urlblock

Disables blocking of all requests sent from the pages matching the rule and disables all $cookie rules.

Příklady

  • @@||example.com^$urlblock — nebudou blokovány žádné požadavky odeslané z example.com a ze všech subdomén.
omezení modifikátoru $urlblock
Omezení

In AdGuard for iOS and AdGuard for Safari, rules with $urlblock work as $document exclusion — unblock everything.

Kompatibilita

Rules with $urlblock modifier are not supported by AdGuard Content Blocker, and AdGuard for Chrome MV3.

Generická pravidla

Before we can proceed to the next modifiers, we have to make a definition of generic rules. The rule is generic if it is not limited to specific domains. Wildcard character * is supported as well.

For example, these rules are generic:

###banner
*###banner
#@#.adsblock
*#@#.adsblock
~domain.com###banner
||domain.com^
||domain.com^$domain=~example.com

And these are not:

domain.com###banner
||domain.com^$domain=example.com

$genericblock

Disables generic basic rules on pages that correspond to exception rule.

Příklady

  • @@||example.com^$genericblock zakáže generická základní pravidla na example.com a všech subdoménách.
omezení modifikátoru $genericblock
Omezení

In AdGuard for iOS and AdGuard for Safari, rules with $genericblock work as $document exclusion — unblock everything.

Kompatibilita

Rules with $genericblock modifier are not supported by AdGuard Content Blocker, and AdGuard for Chrome MV3.

$generichide

Disables all generic cosmetic rules on pages that correspond to the exception rule.

Příklady

  • @@||example.com^$generichide zakáže všechna kosmetická pravidla na example.com a jejích subdoménách.
poznámka

You may use a shorter name (alias) instead of using the full modifier name: $ghide.

specifichide

Disables all specific element hiding and CSS rules, but not general ones. Has an opposite effect to $generichide.

Příklady

  • @@||example.org^$specifichide zakáže example.org##.banner, ale ne ##.banner.
poznámka

You may use a shorter name (alias) instead of using the full modifier name: $shide.

poznámka

All cosmetic rules — not just specific ones — can be disabled by $elemhide modifier.

Kompatibilita

Rules with $specifichide modifier are not supported by AdGuard for iOS, AdGuard for Safari, and AdGuard Content Blocker.

Pokročilé schopnosti

These modifiers are able to completely change the behavior of basic rules.

Modifikátor \ ProduktyAplikace CoreLibsAdGuard pro ChromiumAdGuard pro Chrome MV3AdGuard pro FirefoxAdGuard pro iOSAdGuard pro SafariBlokátor obsahu AdGuard
$all*[1]
$badfilter*[2]
$cookie*[3]
$csp
$hls
$inline-font
$inline-script
$jsonprune
$xmlprune
$network
$permissions*[4]*[4]
$redirect*[5]
$redirect-rule
$referrerpolicy
$removeheader*[7]*[7]*[7]
$removeparam*[6]
$replace
$urltransform
noop
$empty 👎
$mp4 👎
poznámka
  • ✅ — plně podporováno
  • ✅ * — podporováno, ale spolehlivost se může lišit nebo se mohou vyskytnout omezení; více informací naleznete v popisu modifikátoru
  • ❌ — nepodporováno
  • 👎 — zastaralé; stále podporovano, ale v budoucnu bude odstraněno

$all

$all modifier is made of all content-types modifiers and $popup. E.g. rule ||example.org^$all is converting into rule:

||example.org^$document,subdocument,font,image,media,object,other,ping,script,stylesheet,websocket,xmlhttprequest,popup
Omezení

This modifier cannot be used as an exception with the @@ mark.

omezení modifikátoru $all
Omezení

Since $popup is a part if $all, the $all modifier is not supported by AdGuard for Chrome MV3 because of $popup modifier limitations.

Kompatibilita

Rules with $all modifier are not supported by AdGuard Content Blocker.

$badfilter

The rules with the $badfilter modifier disable other basic rules to which they refer. It means that the text of the disabled rule should match the text of the $badfilter rule (without the $badfilter modifier).

Příklady

  • ||example.com$badfilter zakáže ||example.com
  • ||example.com$image,badfilter zakáže ||example.com$image
  • @@||example.com$badfilter zakáže @@||example.com
  • ||example.com$domain=domain.com,badfilter zakáže ||example.com$domain=domain.com

Rules with $badfilter modifier can disable other basic rules for specific domains if they fulfill the following conditions:

  1. Pravidlo má modifikátor $domain
  2. Pravidlo nemá hodnotu modifikátoru negované domény ~ v $domain

In that case, the $badfilter rule will disable the corresponding rule for domains specified in both the $badfilter and basic rules. Please note that wildcard-TLD logic works here as well.

Příklady

  • /some$domain=example.com|example.org|example.io je zakázána pro example.com pomocí /some$domain=example.com,badfilter
  • /some$domain=example.com|example.org|example.io ije zakázána pro example.com a example.org pomocí /some$domain=example.com|example.org,badfilter
  • /some$domain=example.com|example.org a /some$domain=example.io jsou kompletně zakázány pomocí /some$domain=example.com|example.org|example.io,badfilter
  • /some$domain=example.com|example.org|example.io je kompletně zakázána pomocí /some$domain=example.*,badfilter
  • /some$domain=example.* je zakázána pro example.com a example.org pomocí /some$domain=example.com|example.org,badfilter
  • /some$domain=example.com|example.org|example.io NENÍ zakázána pro example.com pomocí /some$domain=example.com|~example.org,badfilter, protože hodnota modifikátoru $domain obsahuje negovanou doménu
omezení modifikátoru $badfilter
Omezení

In AdGuard for Chrome MV3 a rule with the $badfilter modifier is applied in DNR only if it fully cancels the source rule. We cannot calculate it if it is only partially canceled. Examples.

Kompatibilita

Rules with $badfilter modifier are not supported by AdGuard Content Blocker.

The $cookie modifier completely changes rule behavior. Instead of blocking a request, this modifier makes AdGuard suppress or modify the Cookie and Set-Cookie headers.

Multiple rules matching a single request

In case if multiple $cookie rules match a single request, we will apply each of them one by one.

Syntax

$cookie [= name[; maxAge = seconds [; sameSite = strategy ]]]

where:

  • name — nepovinné, řetězec nebo regulární výraz pro přiřazení názvu cookie.
  • seconds — počet sekund aktuálního času pro posunutí data vypršení platnosti souboru cookie.
  • strategy — řetězec pro strategii Same-Site, která se má použít na cookies.

For example,

||example.org^$cookie=NAME;maxAge=3600;sameSite=lax

every time AdGuard encounters a cookie called NAME in a request to example.org, it will do the following:

  • Nastaví datum vypršení platnosti na aktuální čas plus 3600 sekund
  • Přiměje cookie použít "laxní" strategii Same-Site.

Escaping special characters

If regular expression name is used for matching, two characters must be escaped: comma , and dollar sign $. Use backslash \ to escape each of them. For example, escaped comma looks like this: \,.

Příklady

  • ||example.org^$cookie blokuje všechny soubory cookie nastavené doménou example.org; to je ekvivalent nastavení maxAge=0
  • $cookie=__cfduid blokuje všude soubory cookie CloudFlare
  • $cookie=/__utm[a-z]/ blokuje všude soubory cookie Google Analytics
  • ||facebook.com^$third-party,cookie=c_user brání Facebooku ve sledování, i když jste přihlášeni

There are two methods to deactivate $cookie rules: the primary method involves using an exception marked with @@@@||example.org^$cookie. The alternative method employs a $urlblock exception (also included under the $document exception alias — $elemhide,jsinject,content,urlblock,extension). Here's how it works:

  • @@||example.org^$cookie odblokuje všechny soubory cookie nastavené doménou example.org
  • @@||example.org^$urlblock odblokuje všechny cookies nastavené doménou example.org a zakáže blokování všech požadavků odeslaných z example.org
  • @@||example.org^$cookie=concept odblokuje jeden soubor cookie s názvem concept
  • @@||example.org^$cookie=/^_ga_/ odblokuje každý soubor cookie, který odpovídá regulárnímu výrazu
Omezení

In AdGuard for Chrome MV3 we delete cookies in 2 ways: from content-script side (to which we have access) and from onBeforeSendHeaders listener. Since onBeforeSendHeaders and other listeners are no longer blocking, we are not able to delete them in all cases. You can check if a rule works with this test.

Omezení

$cookie rules support these types of modifiers: $domain, $~domain, $important, $third-party, $~third-party, strict-third-party, and strict-first-party.

Kompatibilita

Rules with $cookie modifier are not supported by AdGuard Content Blocker, AdGuard for iOS, and AdGuard for Safari.

$csp

This modifier completely changes the rule behavior. If it is applied to a rule, the rule will not block the matching request. Response headers will be modified instead.

informace

In order to use this type of rules, it is required to have the basic understanding of the Content Security Policy security layer.

For the requests matching a $csp rule, we will strengthen response security policy by enhancing the content security policy, similar to the content security policy of the $csp modifier contents. $csp rules are applied independently from any other rule type. Only document-level exceptions can influence it (see the examples section), but no other basic rules.

Multiple rules matching a single request

In case if multiple $csp rules match a single request, we will apply each of them.

Syntax

$csp value syntax is similar to the Content Security Policy header syntax.

$csp value can be empty in the case of exception rules. See examples section below.

Příklady

  • ||example.org^$csp=frame-src 'none' blokuje všechny obrázky na example.org a jejích subdoménách.
  • @@||example.org/page/*$csp=frame-src 'none' zakáže všechna pravidla s modifikátorem $csp přesně odpovídajícím příznakem frame-src 'none' na všech stránkách odpovídajících vzoru pravidla. Např. výše uvedené pravidlo.
  • @@||example.org/page/*$csp zakáže všechna pravidla $csp na všech stránkách odpovídajících vzoru pravidla.
  • ||example.org^$csp=script-src 'self' 'unsafe-eval' http: https: zakáže vložené skripty na všech stránkách odpovídajících vzoru pravidla.
  • @@||example.org^$document nebo @@||example.org^$urlblock zakáží všechna pravidla $csp na všech stránkách odpovídajících vzoru pravidla.
Omezení
  • V hodnotě $csp je zakázáno několik znaků: ,, $.
  • $csp pravidla podporují tři typy modifikátorů: $domain, $important, $subdocument.
  • Pravidla s direktivami report-* jsou považována za neplatná.
Kompatibilita

Rules with $csp modifier are not supported by AdGuard Content Blocker, AdGuard for iOS and AdGuard for Safari.

$hls

$hls rules modify the response of a matching request. They are intended as a convenient way to remove segments from HLS playlists (RFC 8216).

poznámka

The word "segment" in this document means either a "Media Segment" or a "playlist" as part of a "Master Playlist": $hls rules do not distinguish between a "Master Playlist" and a "Media Playlist".

Syntax

  • ||example.org^$hls=urlpattern odstraní segmenty, jejichž adresa URL odpovídá vzoru adresy URL urlpattern. Vzor funguje stejně jako v základních pravidlech pro URL adresy, ale znaky /, $ a , musí být uvozeny pomocí \ uvnitř urlpattern.
  • ||example.org^$hls=/regexp/options odstraní segmenty, kde URL nebo jeden ze znaků (u určitých možností, pokud jsou přítomny) odpovídá regulárnímu výrazu regexp. K dispozici jsou tyto možnosti options:
    • t — namísto testování adresy URL segmentu otestujte každý znak segmentu podle regulárního výrazu. Segment se shodným znakem je odstraněn;
    • i — regulární výraz nerozlišuje velká a malá písmena.

The characters /, $ and , must be escaped with \ inside regexp.

Výjimky

Basic URL exceptions shall not disable rules with the $hls modifier. They can be disabled as described below:

  • @@||example.org^$hls zakáže všechna pravidla $hls pro odpovědi z URL odpovídajících ||example.org^.
  • @@||example.org^$hls=text zakáže všechna pravidla $hls s hodnotou modifikátoru $hls shodným s text pro odpovědi z URL odpovídajících ||example.org^.
tip

$hls rules can also be disabled by $document, $content and $urlblock exception rules.

poznámka

When multiple $hls rules match the same request, their effect is cumulative.

Příklady

  • ||example.org^$hls=\/videoplayback^?*&source=dclk_video_ads odstraní všechny segmenty se shodnou URL.
  • ||example.org^$hls=/\/videoplayback\/?\?.*\&source=dclk_video_ads/i dosáhne víceméně téhož pomocí regulárního výrazu namísto vzoru URL.
  • ||example.org^$hls=/#UPLYNK-SEGMENT:.*\,ad/t odstraní všechny segmenty, které mají odpovídající znak.

Anatomy of an HLS playlist

A quick summary of the specification:

  1. Seznam stop HLS je kolekce textových řádků
  2. Řádek může být prázdný, komentář (začíná #), znak (také začíná #, lze jej rozpoznat pouze podle názvu) nebo URL
  3. Řádek URL se nazývá "segment"
  4. Znaky se mohou vztahovat na jeden segment, tj. první řádek adresy URL za znakem, na všechny segmenty následující za znakem až do znaku se stejným názvem nebo na celý seznam skladeb

Some points specific to the operation of $hls rules:

  1. Při odstranění segmentu se odstraní také všechny znaky, které se vztahují pouze k tomuto segmentu
  2. Pokud se znak vztahuje na více segmentů a všechny tyto segmenty jsou odstraněny, je odstraněna i znak
  3. Protože neexistuje způsob, jak rozpoznat různé druhy znaků podle syntaxe, rozpoznáváme všechny znaky uvedené v RFC a některé nestandardní znaky, se kterými jsme se setkali v praxi. Všechny řádky začínající na #. Ty, které nejsou rozpoznány jako znak, jsou předány bez úprav a nejsou porovnávány s pravidly
  4. Značky nebudou přiřazeny, pokud se vztahují na celý seznam stop a k jejich odstranění nelze použít pravidla $hls, protože tyto typy pravidel jsou určeny pro odstraňování segmentů. Pokud víte, co děláte, můžete pomocí pravidel $replace odstranit nebo přepsat pouze jeden znak ze seznamu skladeb

An example of a transformation done by the rules:

Original response
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXTINF,5
preroll.ts
#UPLYNK-SEGMENT:abc123,ad
#UPLYNK-KEY:aabb1122
#EXT-X-DISCONTINUITY
#EXTINF,10
01.ts
#EXTINF,10
02.ts
#UPLYNK-SEGMENT:abc123,segment
#UPLYNK-KEY:ccdd2233
#EXT-X-DISCONTINUITY
#EXTINF,10
01.ts
#EXTINF,10
02.ts
#EXT-X-ENDLIST
Applied rules
||example.org^$hls=preroll
||example.org^$hls=/#UPLYNK-SEGMENT:.*\,ad/t
Modified response
#EXTM3U
#EXT-X-TARGETDURATION:10
#UPLYNK-SEGMENT:abc123,segment
#UPLYNK-KEY:ccdd2233
#EXT-X-DISCONTINUITY
#EXTINF,10
01.ts
#EXTINF,10
02.ts
#EXT-X-ENDLIST
Omezení
  • Pravidla s modifikátorem $hls lze použít pouze v důvěryhodných filtrech.
  • $hls pravidla jsou kompatibilní pouze s těmito modifikátory: $domain, $third-party, $strict-third-party, $strict-first-party, $app, $important, $match-case a $xmlhttprequest.
  • $hls pravidla platí pouze pro seznamy stop HLS, což je text kódovaný v UTF-8 začínající řádkem #EXTM3U. Jakákoli jiná odpověď nebude těmito pravidly upravena.
  • Pravidla $hls neplatí, pokud je velikost původní odpovědi větší než 10 MB.
Kompatibilita

Rules with the $hls modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.10 or later.

$inline-script

The $inline-script modifier is designed to block inline JavaScript embedded into the web page, using Content Security Policy (CSP). It improves security and privacy by preventing application of inline ads or potentially malicious scripts. The rule ||example.org^$inline-script is converting into the CSP-syntax rule:

||example.org^$csp=script-src 'self' 'unsafe-eval' http: https: data: blob: mediastream: filesystem:

$inline-font

The $inline-font modifier is designed to block inline fonts embedded into the web page, using Content Security Policy (CSP). It improves security and privacy by preventing application of inline fonts that could be used for data collection and fingerprinting. The rule ||example.org^$inline-font is converting into the CSP-syntax rule:

||example.org^$csp=font-src 'self' 'unsafe-eval' http: https: data: blob: mediastream: filesystem:

$jsonprune

$jsonprune rules modify the response to a matching request by removing JSON items that match a modified JSONPath expression. They do not modify responses which are not valid JSON documents.

In AdGuard for Windows, Mac, and Android with CoreLibs v1.11 or later, $jsonprune also supports modifying JSONP (padded JSON) documents.

Syntax

  • ||example.org^$jsonprune=expression odstraní z odpovědi položky, které odpovídají upravenému výrazu JSONPath expression.

Due to the way rule parsing works, the characters $ and , must be escaped with \ inside expression.

The modified JSONPath syntax has the following differences from the original:

  1. Výrazy skriptů nejsou podporovány
  2. Podporované výrazy filtrů jsou:
    • ?(has <key>) — "true", pokud má aktuální objekt zadaný klíč
    • ?(key-eq <key> <value>) — "true", pokud má aktuální objekt zadaný klíč a jeho hodnota se rovná zadané hodnotě
    • ?(key-substr <key> <value>) — "true", pokud je zadaná hodnota podřetězcem hodnoty zadaného klíče aktuálního objektu
  3. Mezery mimo řetězce s dvojitými nebo jednoduchými uvozovkami nemají žádný význam
  4. Lze použít řetězce s dvojitými i jednoduchými uvozovkami
  5. Výrazy končící na .. nejsou podporovány
  6. V hranatých závorkách lze zadat vícero dílků pole

There are various online tools that make working with JSONPath expressions more convenient:

https://www.site24x7.com/tools/jsonpath-finder-validator.html https://jsonpathfinder.com/ https://jsonpath.com/

Keep in mind, though, that all JSONPath implementations have unique features/quirks and are subtly incompatible with each other.

Výjimky

Basic URL exceptions shall not disable rules with the $jsonprune modifier. They can be disabled as described below:

  • @@||example.org^$jsonprune zakáže všechna pravidla $jsonprune pro odpovědi z URL odpovídajících ||example.org^.
  • @@||example.org^$jsonprune=text zakáže všechna pravidla $jsonprune s hodnotou modifikátoru $jsonprune shodným s text pro odpovědi z URL odpovídajících ||example.org^.

$jsonprune rules can also be disabled by $document, $content and $urlblock exception rules.

poznámka

When multiple $jsonprune rules match the same request, they are sorted in lexicographical order, the first rule is applied to the original response, and each of the remaining rules is applied to the result of applying the previous one.

Příklady

  • ||example.org^$jsonprune=\$..[one\, "two three"] odstraní všechny výskyty klíčů "one" a "two three" kdekoli v dokumentu JSON.
Input
{
"one": 1,
"two": {
"two three": 23,
"four five": 45
}
}
Output
{
"two": {
"four five": 45
}
}
  • ||example.org^$jsonprune=\$.a[?(has ad_origin)] odstraní všechny potomky a, které mají klíč ad_origin.
Input
{
"a": [
{
"ad_origin": "https://example.org",
"b": 42
},
{
"b": 1234
}
]
}
Output
{
"a": [
{
"b": 1234
}
]
}
  • ||example.org^$jsonprune=\$.*.*[?(key-eq 'Some key' 'Some value')] odstraní všechny položky, které jsou na úrovni vnoření 3 a mají vlastnost "Some key" rovnu "Some value".
Input
{
"a": {"b": {"c": {"Some key": "Some value"}, "d": {"Some key": "Other value"}}},
"e": {"f": [{"Some key": "Some value"}, {"Some key": "Other value"}]}
}
Output
{
"a": {"b": {"d": {"Some key": "Other value"}}},
"e": {"f": [{"Some key": "Other value"}]}
}

Nested JSONPath expressions

In AdGuard for Windows, Mac and Android with CoreLibs v1.11 or later, JSONPath expressions may be used as keys in filter expressions.

  • ||example.org^$jsonprune=\$.elems[?(má "\$.abc")] odstraní všechny potomky elems, které mají vlastnost volitelnou výrazem JSONPath $.abc.
Input
{
"elems": [
{
"a": {"b": {"c": 123}},
"k": "v"
},
{
"d": {"e": {"f": 123}},
"k1": "v1"
}
]
}
Output
{
"elems": [
{
"d": {"e": {"f": 123}},
"k1": "v1"
}
]
}
  • ||example.org^$jsonprune=\$.elems[?(key-eq "\$.a.b.c" "abc")] odstraní všechny potomky elems, které mají vlastnost volitelnou pomocí výrazu JSONPath $.a.b.c s hodnotou rovnou "abc".
Input
{
"elems": [
{
"a": {"b": {"c": 123}},
},
{
"a": {"b": {"c": "abc"}}
}
]
}
Output
{
"elems": [
{
"a": {"b": {"c": 123}}
}
]
}
Omezení
  • $jsonprune pravidla jsou kompatibilní pouze s těmito modifikátory: $domain, $third-party, $strict-third-party, $strict-first-party, $app, $important, $match-case a $xmlhttprequest.
  • Pravidla $jsonprune neplatí, pokud je velikost původní odpovědi větší než 10 MB.
Kompatibilita

Rules with the $jsonprune modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.10 or later.

$xmlprune

$xmlprune rules modify the response to a matching request by removing XML items that match an XPath 1.0 expression. The expression must return a node-set. $xmlprune rules do not modify responses which are not well-formed XML documents.

Syntax

  • ||example.org^$xmlprune=expression odstraní z odpovědi položky, které odpovídají výrazu XPath expression.

Due to the way rule parsing works, the characters $ and , must be escaped with \ inside expression.

Výjimky

Basic URL exceptions shall not disable rules with the $xmlprune modifier. They can be disabled as described below:

  • @@||example.org^$xmlprune zakáže všechna pravidla $xmlprune pro odpovědi z URL odpovídajících ||example.org^.
  • @@||example.org^$xmlprune=text zakáže všechna pravidla $xmlprune s hodnotou modifikátoru $xmlprune shodným s text pro odpovědi z URL odpovídajících ||example.org^.

$xmlprune rules can also be disabled by $document, $content and $urlblock exception rules.

poznámka

When multiple $xmlprune rules match the same request, they are applied in lexicographical order.

Příklady

  • ||example.org^$xmlprune=/bookstore/book[position() mod 2 = 1] odstraní z knihkupectví knihy s lichými čísly.
Input
<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>

<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>

</bookstore>
Output
<?xml version="1.0" encoding="UTF-8"?>

<bookstore>



<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>



<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>

</bookstore>
  • ||example.org^$xmlprune=/bookstore/book[year = 2003] odstraní knihy z roku 2003 z knihkupectví.
Input
<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>

<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>

</bookstore>
Output
<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>





</bookstore>
  • ||example.org^$xmlprune=//*/@* odstraní všechny atributy ze všech prvků.
Input
<?xml version="1.0" encoding="UTF-8"?>

<bookstore location="cy">

<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

</bookstore>
Output
<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

</bookstore>
Omezení
  • $xmlprune pravidla jsou kompatibilní pouze s těmito modifikátory: $domain, $third-party, $strict-third-party, $strict-first-party, $app, $important, $match-case a $xmlhttprequest.
  • Pravidla $xmlprune neplatí, pokud je velikost původní odpovědi větší než 10 MB.
Kompatibilita

Rules with the $xmlprune modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.15 or later.

$network

This is basically a Firewall-like rule allowing to fully block or unblock access to a specified remote address.

  1. Pravidla $network odpovídají pouze IP adresám! Nelze je použít k zablokování nebo odblokování přístupu k doméně.
  2. Chcete-li se shodovat s adresou IPv6, musíte použít sbalenou syntaxi, např. [2001:4860:4860::8888]$network namísto [2001:4860:4860:0:0:0:0:8888]$network.
  3. Pravidlo seznamu povolených $network způsobí, že AdGuard bude obcházet data odpovídajícího koncového bodu, proto nebude provádět žádné další filtrování.
  4. Pokud část IP začíná a končí znakem /, je považována za regulární výraz.

We recommend to get acquainted with this article for better understanding of regular expressions.

Omezení

The $network modifier can only be used in rules together with the $app and $important modifiers, and not with any other modifiers.

Příklady

  • 174.129.166.49:3478^$network blokuje přístup k 174.129.166.49:3478 (ale ne k 174.129.166.49:34788).
  • [2001:4860:4860::8888]:443^$network blokuje přístup k [2001:4860:4860::8888]:443.
  • 174.129.166.49$network blokuje přístup k 174.129.166.49:*.
  • @@174.129.166.49$network způsobí, že AdGuard bude koncovému bodu předávat data. Žádná jiná pravidla se neuplatňují.
  • /.+:3[0-9]{4}/$network blokuje přístup k libovolnému portu od 30000 do 39999.
  • /8.8.8.(:?8|4)/$network blokuje přístup k 8.8.8.8 a 8.8.8.4.
Kompatibilita

Only AdGuard for Windows, Mac, and Android are technically capable of using rules with $network modifier.

$permissions

This modifier completely changes the rule behavior. If it is applied to a rule, the rule will not block the matching request. Response headers will be modified instead.

informace

In order to use this type of rules, it is required to have a basic understanding of the Permissions Policy security layer.

For the requests matching a $permissions rule, AdGuard strengthens response's permissions policy by adding an additional permission policy equal to the $permissions modifier contents. $permissions rules are applied independently from any other rule type. Only document-level exceptions can influence it (see the examples section), but no other basic rules.

Syntax

$permissions value syntax is identical to that of the Permissions-Policy header syntax with the following exceptions:

  1. Čárka, která odděluje více prvků MUSÍ být uvozena – viz příklady níže.
  2. Místo čárky lze pro oddělení funkcí použít znak (|).

The list of available directives is available here.

$permissions value can be empty in the case of exception rules — see examples below.

Příklady

  • ||example.org^$permissions=autoplay=() zakáže automatické přehrávání médií vyžádaných prostřednictvím rozhraní HTMLMediaElement v rámci example.org.
  • @@||example.org/page/*$permissions=autoplay=() zakáže všechna pravidla s modifikátorem $permissions přesně odpovídajícím příznakem autoplay=() na všech stránkách odpovídajících vzoru pravidla. Např. výše uvedené pravidlo. Je důležité si uvědomit, že pravidlo výjimky se projeví pouze v případě přesné shody hodnot. Pokud například chcete zakázat pravidlo $permissions=a=()\,b=(), potřebujete pravidlo výjimky @@$permissions=a=()\,b=() a ne @@$permissions=b=()\,a=() ani @@$permissions=b=(), protože b=()\,a=() nebo b=() neodpovídá a=()\,b=().
  • @@||example.org/page/*$permissions zakáže všechna pravidla $permissions na všech stránkách odpovídajících vzoru pravidla.
  • $domain=example.org|example.com,permissions=storage-access=()\, camera=() zakáže použití API pro přístup k úložišti pro vyžádání přístupu k nerozděleným souborům cookies a používání vstupních zařízení videa napříč example.org a example.com.
  • $domain=example.org|example.com,permissions=storage-access=()|camera=() dělá totéž — místo čárky lze k oddělení funkcí použít |.
  • @@||example.org^$document nebo @@||example.org^$urlblock zakáží všechna pravidla $permission na všech stránkách odpovídajících vzoru pravidla.
poznámka

$permissions rules only take effect for main frame and sub frame requests. This means they are applied when a page is loaded or when an iframe is loaded.

poznámka

If there are multiple $permissions rules that match the same request, multiple Permissions-Policy headers will be added to the response for each rule with their $permissions value. So if you have two rules: ||example.org^$permissions=autoplay=() and ||example.org^$permissions=geolocation=()\,camera=() that match the same request, the response will contain two Permissions-Policy headers: autoplay=() and geolocation=()\,camera=().

omezení modifikátoru $permissions
Omezení

Firefox ignores the Permissions-Policy header. For more information, see this issue.

Omezení
  1. Zakázané znaky v $permissions hodnotě: $.
  2. $permissions je kompatibilní s omezenou sadou modifikátorů: $domain, $important, $subdocument a modifikátory typu obsahu.
  3. Pravidla $permissions, která neobsahují žádné modifikátory typu obsahu , budou odpovídat pouze požadavkům, jejichž typem obsahu je document.
Kompatibilita
  • Rules with the $permissions modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.11 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.
  • Pipe separator | instead of escaped comma is supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.14 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.

$redirect

AdGuard is able to redirect web requests to a local "resource".

Syntax

AdGuard uses the same filtering rule syntax as uBlock Origin. Also, it is compatible with ABP $rewrite=abp-resource modifier.

$redirect is a modifier for the basic filtering rules so rules with this modifier support all other basic modifiers like $domain, $third-party, $script, etc.

The value of the $redirect modifier must be the name of the resource that will be used for redirection.

Zakázání pravidel $redirect
  • ||example.org/script.js$script,redirect=noopjs — toto pravidlo přesměruje všechny požadavky na example.org/script.js na zdroj s názvem noopjs.
  • ||example.org/test.mp4$media,redirect=noopmp4-1s — toto pravidlo přesměruje všechny požadavky na example.org/test.mp4 na zdroj s názvem noopmp4-1s.
  • @@||example.org^$redirect zakáže všechna pravidla $redirect pro URL adresy, které odpovídají ||example.org^.
  • @@||example.org^$redirect=nooptext zakáže všechna pravidla s $redirect=nooptext pro všechny požadavky, které odpovídají ||example.org^.

More information on redirects and their usage is available on GitHub.

Priority pravidel $redirect

$redirect rules have higher priority than regular basic blocking rules. This means that if there is a basic blocking rule, the $redirect rule will override it. Allowlist rules with @@ mark have higher priority than $redirect rules. If a basic rule with the $important modifier and the $redirect rule matches the same URL, the latter is overridden unless it's also marked as $important.

In short: $important > @@ > $redirect > basic rules.

Go to rules priorities for more details.

omezení modifikátoru $redirect
Omezení

In AdGuard for Chrome MV3 allowlist rules with $redirect are not supported.

Kompatibilita

$redirect-rule

This is basically an alias to $redirect since it has the same "redirection" values and the logic is almost similar. The difference is that $redirect-rule is applied only in the case when the target request is blocked by a different basic rule.

Go to rules priorities for more details.

Negating $redirect-rule works exactly the same way as for regular $redirect rules. Even more than that, @@||example.org^$redirect will negate both $redirect and $redirect-rule rules.

Příklady

||example.org/script.js
||example.org^$redirect-rule=noopjs

In this case, only requests to example.org/script.js will be "redirected" to noopjs. All other requests to example.org will be kept intact.

$referrerpolicy

These rules allow overriding of a page's referrer policy. Responses to matching requests will have all of their Referrer-Policy headers replaced with a single header with the value equal to the matching rule's modifier value. If the response carries an HTML document with a <meta name="referrer"... tag, the content attribute of the tag will also be replaced with the modifier value.

An exception rule with a modifier value disables the blocking rule with the same modifier value. An exception rule without a modifier value disables all matched referrer-policy rules.

If a request matches multiple $referrerpolicy rules not disabled by exceptions, only one of them (it is not specified which one) is applied. $referrerpolicy rules without specified content-type modifiers apply to $document and $subdocument content types.

Příklady

  • ||example.com^$referrerpolicy=unsafe-url přepíše zásady odkazování pro example.com pomocí unsafe-url.
  • @@||example.com^$referrerpolicy=unsafe-url zakáže předchozí pravidlo.
  • @@||example.com/abcd.html^$referrerpolicy zakáže všechna pravidla $referrerpolicy na example.com/abcd.html.
Kompatibilita

Rules with the $referrerpolicy modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.12 or later.

$removeheader

Rules with $removeheader modifier are intended to remove headers from HTTP requests and responses. The initial motivation for this rule type is to be able to get rid of the Refresh header which is often used to redirect users to an undesirable location. However, this is not the only case where this modifier can be useful.

Just like $csp, $redirect, $removeparam, and $cookie, this modifier exists independently, rules with it do not depend on the regular basic rules, i.e. regular exception or blocking rules will not affect it. By default, it only affects response headers. However, you can also change it to remove headers from HTTP requests as well.

Syntax

Basic syntax

  • ||example.org^$removeheader=header-name odstraní odpověď záhlaví s názvem header-name
  • ||example.org^$removeheader=request:header-name odstraní požadavek záhlaví s názvem header-name

$removeheader is case-insensitive, but we suggest always using lower case.

Negating $removeheader

This type of rules works pretty much the same way it works with $csp and $redirect modifiers.

Use @@ to negate $removeheader:

  • @@||example.org^$removeheader neguje všechna pravidla $removeheader pro URL adresy, které odpovídají ||example.org^.
  • @@||example.org^$removeheader=header neguje všechna pravidla s $removeheader=header pro jakýkoliv požadavek, který odpovídá ||example.org^.

$removeheader rules can also be disabled by $document and $urlblock exception rules. But basic exception rules without modifiers will not do that. For example, @@||example.com^ will not disable $removeheader=p for requests to example.com, but @@||example.com^$urlblock will.

poznámka

In case of multiple $removeheader rules matching a single request, we will apply each of them one by one.

Příklady

  • ||example.org^$removeheader=refresh odstraní záhlaví Refresh ze všech HTTP odpovědí vrácených doménou example.org a jejími subdoménami.

  • ||example.org^$removeheader=request:x-client-data odstraní záhlaví X-Client-Data ze všech požadavků HTTP.

  • Další blok pravidel odstraní záhlaví Refresh a Location ze všech odpovědí HTTP vrácených doménou example.org s výjimkou požadavků na example.org/path/*, u kterých nebudou odstraněny žádné záhlaví:

    ||example.org^$removeheader=refresh
    ||example.org^$removeheader=location
    @@||example.org/path/$removeheader
omezení modifikátoru $removeheader
Omezení

AdGuard for Chrome MV3 has some limitations:

  • Pravidla negace a seznamu povolených nejsou podporována.

  • Skupina podobných $removeheader pravidel bude sloučena do jednoho dekorativního pravidla. Např:

    ||testcases.adguard.com$xmlhttprequest,removeheader=p1case1
    ||testcases.adguard.com$xmlhttprequest,removeheader=P2Case1
    $xmlhttprequest,removeheader=p1case2
    $xmlhttprequest,removeheader=P2case2

    je převedeno na

    [
    {
    "id": 1,
    "action": {
    "type": "modifyHeaders",
    "responseHeaders": [
    {
    "header": "p1case1",
    "operation": "remove"
    },
    {
    "header": "P2Case1",
    "operation": "remove"
    },
    ]
    },
    "condition": {
    "urlFilter": "||testcases.adguard.com",
    "resourceTypes": [
    "xmlhttprequest"
    ]
    }
    },
    {
    "id": 2,
    "action": {
    "type": "modifyHeaders",
    "responseHeaders": [
    {
    "header": "p1case2",
    "operation": "remove"
    },
    {
    "header": "P2case2",
    "operation": "remove"
    }
    ]
    },
    "condition": {
    "resourceTypes": [
    "xmlhttprequest"
    ]
    }
    }
    ]
Omezení

This type of rules can only be used in trusted filters.

  1. Aby nedošlo k narušení bezpečnosti, nelze z níže uvedeného seznamu odstranit záhlaví $removeheader:

    • access-control-allow-origin
    • access-control-allow-credentials
    • access-control-allow-headers
    • access-control-allow-methods
    • access-control-expose-headers
    • access-control-max-age
    • access-control-request-headers
    • access-control-request-method
    • origin
    • timing-allow-origin
    • allow
    • cross-origin-embedder-policy
    • cross-origin-opener-policy
    • cross-origin-resource-policy
    • content-security-policy
    • content-security-policy-report-only
    • expect-ct
    • feature-policy
    • origin-isolation
    • strict-transport-security
    • upgrade-insecure-requests
    • x-content-type-options
    • x-download-options
    • x-frame-options
    • x-permitted-cross-domain-policies
    • x-powered-by
    • x-xss-protection
    • public-key-pins
    • public-key-pins-report-only
    • sec-websocket-key
    • sec-websocket-extensions
    • sec-websocket-accept
    • sec-websocket-protocol
    • sec-websocket-version
    • p3p
    • sec-fetch-mode
    • sec-fetch-dest
    • sec-fetch-site
    • sec-fetch-user
    • referrer-policy
    • content-type
    • content-length
    • accept
    • accept-encoding
    • host
    • connection
    • transfer-encoding
    • upgrade
  2. $removeheader pravidla jsou kompatibilní pouze s těmito modifikátory: $domain, $third-party, $strict-third-party, $strict-first-party, $app, $important, $match-case a modifikátory typu obsahu jako $script a $stylesheet. Pravidla s jinými modifikátory jsou považována za neplatná a budou vyřazena.

Kompatibilita

Rules with $removeheader modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard Browser Extension for Chrome, Firefox, and Edge.

$removeparam

poznámka

$queryprune is an alias of $removeparam. Since $queryprune is deprecated, avoid using it and use $removeparam instead.

Rules with $removeparam modifier are intended to strip query parameters from requests' URLs. Please note that such rules are only applied to GET, HEAD, OPTIONS, and sometimes POST requests.

Syntax

Basic syntax

  • $removeparam=param odstraní parametr dotazu s názvem param z URL libovolného požadavku, např. požadavek na http://example.com/page?param=1&another=2 bude transformován na http://example.com/page?another=2.

Regular expressions

You can also use regular expressions to match query parameters and/or their values:

  • $removeparam=/regexp/[options] — odstraní parametry dotazu, které odpovídají regulárnímu výrazu regexp z adres URL jakéhokoli požadavku. Na rozdíl od základní syntaxe to znamená "odebrat parametry dotazu normalizované na řetězec name=value, který odpovídá regulárnímu výrazu regexp ". [options] zde je seznam možností regulárních výrazů. V současné době je jedinou podporovanou možností i, díky čemuž se nerozlišují malá a velká písmena.

Escaping special characters

Special characters should be URL-encoded in a rule to correctly match the URL text.

For example, to remove ?$param=true, you should use the $removeparam=%24param rule.

poznámka

Spaces and commas should also be URL-encoded, otherwise the rule won't match the URL. However, ., -, _, and ~ should be used as they are, since they are not marked as reserved characters in URL encoding.

Remember to escape special characters like . in the regular expressions. Use the \ character to do this. For example, an escaped dot should look like this: \..

poznámka

Regexp-type rules apply to both the name and value of the parameter. To minimize errors, it is safer to start each regexp with /^, unless you are specifically targeting parameter values.

Remove all query parameters

Specify naked $removeparam to remove all query parameters:

  • ||example.org^$removeparam — odstraní všechny parametry dotazu z adres URL odpovídajících ||example.org^.

Inversion

Use ~ to apply inversion:

  • $removeparam=~param — odstraní všechny parametry dotazu s názvem odlišným od param.
  • $removeparam=~/regexp/ — odstraní všechny parametry dotazu, které neodpovídají regulárnímu výrazu regexp.
poznámka

If ~ does not appear at the beginning of the rule, it is treated as a symbol in the text.

Negating $removeparam

This sort of rules work pretty much the same way it works with $csp and $redirect modifiers.

Use @@ to negate $removeparam:

  • @@||example.org^$removeparam neguje všechna pravidla $removeparam pro URL adresy, které odpovídají ||example.org^.
  • @@||example.org^$removeparam=param neguje všechna pravidla s $removeparam=param pro jakýkoliv požadavek, který odpovídá ||example.org^.
  • @@||example.org^$removeparam=/regexp/ neguje všechna pravidla s $removeparam=/regexp/ pro jakýkoliv požadavek, který odpovídá ||example.org^.

Multiple rules matching a single request

In the case when multiple $removeparam rules match a single request, each of them will be applied one by one.

Příklady

$removeparam=/^(utm_source|utm_medium|utm_term)=/
$removeparam=/^(utm_content|utm_campaign|utm_referrer)=/
@@||example.com^$removeparam

With these rules some UTM parameters will be stripped out from any request, except that requests to example.com will not be stripped at all, e.g. http://google.com/page?utm_source=s&utm_referrer=fb.com&utm_content=img will be transformed to http://google.com/page, but http://example.com/page?utm_source=s&utm_referrer=fb.com&utm_content=img will not be affected by the blocking rule.

  • $removeparam=utm_source odstraní parametr dotazu utm_source ze všech požadavků.

  • $removeparam=/utm_.*/ odstraní všechny parametry utm_* query z URL libovolného požadavku, např. požadavek na http://example.com/page?utm_source=test bude transformován na http://example.com/page.

  • $removeparam=/^utm_source=campaign$/ odstraní parametr dotazu utm_source s hodnotou rovnou campaign. Nemá vliv na ostatní parametry utm_source.

Negating one $removeparam rule and replacing it with a different rule

$removeparam=/^(gclid|yclid|fbclid)=/
@@||example.com^$removeparam=/^(gclid|yclid|fbclid)=/
||example.com^$removeparam=/^(yclid|fbclid)=/

With these rules, Google, Yandex, and Facebook Click IDs will be removed from all requests. There is one exception: Google Click ID (gclid) will not be removed from requests to example.com.

Negating $removeparam for all parameters

$removeparam=/^(utm_source|utm_medium|utm_term)=/
$removeparam=/^(utm_content|utm_campaign|utm_referrer)=/
@@||example.com^$removeparam

With these rules, specified UTM parameters will be removed from any request save for requests to example.org.

$removeparam rules can also be disabled by $document and $urlblock exception rules. But basic exception rules without modifiers do not do that. For example, @@||example.com^ will not disable $removeparam=p for requests to example.com, but @@||example.com^$urlblock will.

omezení modifikátoru $removeparam
Omezení

AdGuard for Chrome MV3 has some limitations:

  • Regulární výrazy, negace a pravidla seznamu povolených nejsou podporovány.

  • Skupina podobných $removeparam budou sloučena do jedné. Příklad:

    ||testcases.adguard.com$xmlhttprequest,removeparam=p1case1
    ||testcases.adguard.com$xmlhttprequest,removeparam=p2case1
    ||testcases.adguard.com$xmlhttprequest,removeparam=P3Case1
    $xmlhttprequest,removeparam=p1case2

    je převedeno na

    [
    {
    "id": 1,
    "action": {
    "type": "redirect",
    "redirect": {
    "transform": {
    "queryTransform": {
    "removeParams": [
    "p1case1",
    "p2case1",
    "P3Case1"
    ]
    }
    }
    }
    },
    "condition": {
    "urlFilter": "||testcases.adguard.com",
    "resourceTypes": [
    "xmlhttprequest"
    ],
    "isUrlFilterCaseSensitive": false
    }
    },
    {
    "id": 4,
    "action": {
    "type": "redirect",
    "redirect": {
    "transform": {
    "queryTransform": {
    "removeParams": [
    "p1case2"
    ]
    }
    }
    }
    },
    "condition": {
    "resourceTypes": [
    "xmlhttprequest"
    ],
    "isUrlFilterCaseSensitive": false
    }
    }
    ]
Omezení
  1. Pravidla s modifikátorem $removeparam lze použít pouze v důvěryhodných filtrech.
  2. Pravidla $removeparam jsou kompatibilní se základními modifikátory, modifikátory typu obsahu a s modifikátory $important a $app. Pravidla s jinými modifikátory jsou považována za neplatná a budou vyřazena.
  3. Pravidla $removeparam, která neobsahují žádné modifikátory typu obsahu, budou odpovídat pouze požadavkům, jejichž typem obsahu je document.
Kompatibilita
  • Rules with $removeparam modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.7 or later, and AdGuard Browser Extension v3.6 or later.
  • $removeparam syntax for regular expressions is supported AdGuard for Windows, AdGuard for Mac, and AdGuard for Android with CoreLibs v1.8 or later, and AdGuard Browser Extension v4.0 or later.
  • POST request types are supported only by AdGuard for Windows, Mac, and Android with CoreLibs v1.10 or later, and AdGuard Browser Extension with TSWebExtension v0.4.6 or later.

$replace

This modifier completely changes the rule behavior. If it is applied, the rule will not block the request. The response is going to be modified instead.

You will need some knowledge of regular expressions to use $replace modifier.

Features

  • Pravidla $replace platí pro jakoukoli textovou odpověď, ale neplatí pro binární (media, image, object atd.).
  • $replace rules have a higher priority than other basic rules, including exception rules. So if a request matches two different rules, one of which has the $replace modifier, this rule will be applied.
  • Pravidla výjimek na úrovni dokumentu s modifikátory $content nebo $document zakáží pravidla $replace pro požadavky, které jim odpovídají.
  • Ostatní pravidla výjimek na úrovni dokumentu ($generichide, $elemhide nebo modifikátory $jsinject) se uplatňují vedle pravidel $replace. To znamená, že můžete upravit obsah stránky pomocí pravidla $replace a zároveň zde zakázat kosmetická pravidla.

$replace value can be empty in the case of exception rules. See examples section for further information.

Multiple rules matching a single request

In case if multiple $replace rules match a single request, we will apply each of them. The order is defined alphabetically.

Syntax

In general, $replace syntax is similar to replacement with regular expressions in Perl.

replace = "/" regexp "/" replacement "/" modifiers
  • regexp — regulární výraz.
  • replacement — řetězec, který bude použit k nahrazení řetězce odpovídajícího regexp.
  • modifiers — příznaky regulárního výrazu. Například i — necitlivé vyhledávání nebo s — jednořádkový režim.

In the $replace value, two characters must be escaped: comma , and dollar sign $. Use backslash \ for it. For example, an escaped comma looks like this: \,.

Příklady

||example.org^$replace=/(<VAST[\s\S]*?>)[\s\S]*<\/VAST>/\$1<\/VAST>/i

There are three parts in this rule:

  • regexp(<VAST(.|\s)*?>)(.|\s)*<\/VAST>;
  • replacement\$1<\/VAST> kde $ je uvozeno;
  • modifiersi pro necitlivé vyhledávání.

You can see how this rule works here: http://regexr.com/3cesk

Multiple $replace rules

  1. ||example.org^$replace=/X/Y/
  2. ||example.org^$replace=/Z/Y/
  3. @@||example.org/page/*$replace=/Z/Y/
  • Jak pravidlo 1, tak pravidlo 2 se použijí na všechny požadavky odeslané na example.org.
  • Pravidlo 2 je zakázáno pro požadavky odpovídající na ||example.org/page/, ale pravidlo 1 stále funguje!

Disabling $replace rules

  • @@||example.org^$replace zakáže všechna pravidla $replace odpovídající na ||example.org^.
  • @@||example.org^$document nebo @@||example.org^$content zakáže všechna pravidla $replace pocházející ze stránek example.org včetně stránky samotné.
Omezení
  • Rules with the $replace modifier can only be used in trusted filters.
  • Pravidla $replace neplatí, pokud je velikost původní odpovědi větší než 10 MB. For AdGuard Browser Extension, this limit applies starting from v5.2 or later.
Kompatibilita

Rules with $replace modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard Browser Extension for Firefox. Such rules do not work in extensions for other browsers because they are unable to modify content on the network level.

$urltransform

The $urltransform rules allow you to modify the request URL by replacing text matched by a regular expression.

Features

  • Pravidla $urltransform se obvykle vztahují pouze na části URL týkající se cesty a dotazu, viz níže jedna výjimka.
  • $urltransform nebude použito, pokud je původní URL blokována jinými pravidly.
  • $urltransform se použije před pravidly $removeparam.

The $urltransform value can be empty for exception rules.

Multiple rules matching a single request

If multiple $urltransform rules match a single request, we will apply each of them. The order is defined alphabetically.

Syntax

$urltransform syntax is similar to replacement with regular expressions in Perl.

urltransform = "/" regexp "/" replacement "/" modifiers
  • regexp — regulární výraz.
  • replacement — řetězec, který bude použit k nahrazení řetězce odpovídajícího regexp.
  • modifiers — příznaky regulárního výrazu. Například i — necitlivé vyhledávání nebo s — jednořádkový režim.

In the $urltransform value, two characters must be escaped: the comma , and the dollar sign $. Use the backslash character \ for this. For example, an escaped comma looks like this: \,.

Changing the origin

Kompatibilita

This section only applies to AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.17 or later.

As stated above, normally $urltransform rules are only allowed to change the path and query parts of the URL. However, if the rule's regexp begins with the string ^http, then the full URL is searched and can be modified by the rule. Such a rule will not be applied if the URL transformation can not be achieved via an HTTP redirect (for example, if the request's method is POST).

Příklady

||example.org^$urltransform=/(pref\/).*\/(suf)/\$1\$2/i

There are three parts in this rule:

  • regexp(pref\/).*\/(suf);
  • replacement\$1\$2 kde $ je uvozeno;
  • modifiersi pro necitlivé vyhledávání.

Multiple $urltransform rules

  1. ||example.org^$urltransform=/X/Y/
  2. ||example.org^$urltransform=/Z/Y/
  3. @@||example.org/page/*$urltransform=/Z/Y/
  • Jak pravidlo 1, tak pravidlo 2 se použijí na všechny požadavky odeslané na example.org.
  • Pravidlo 2 je zakázáno pro požadavky odpovídající na ||example.org/page/, ale pravidlo 1 stále funguje!

Re-matching rules after transforming the URL

After applying all matching $urltransform rules, the transformed request will be matched against all other rules:

E.g., with the following rules:

||example.com^$urltransform=/firstpath/secondpath/
||example.com/secondpath^

the request to https://example.com/firstpath will be blocked.

Disabling $urltransform rules

  • @@||example.org^$urltransform zakáže všechna pravidla $urltransform odpovídající na ||example.org^.
  • @@||example.org^$urltransform=/Z/Y/ zakáže pravidlo s $urltransform=/Z/Y/ pro jakýkoliv požadavek, který odpovídá ||example.org^.

$urltransform rules can also be disabled by $document and $urlblock exception rules. But basic exception rules without modifiers do not do that. For example, @@||example.com^ will not disable $urltransform=/X/Y/ for requests to example.com, but @@||example.com^$urlblock will.

The rule example for cleaning affiliate links

Many websites use tracking URLs to monitor clicks before redirecting to the actual destination. These URLs contain marketing parameters and analytics tokens that can be removed to improve privacy.

Below is an example of how to obtain the clean destination link to bypass tracking websites and go directly to the destination.

In our example:

  1. Počáteční URL (se sledováním kliknutí): https://www.aff.example.com/visit?url=https%3A%2F%2Fwww.somestore.com%2F%26referrer%3Dhttps%3A%2F%2Fwww.aff.example.com%2F%26ref%3Dref-123
  2. Sledování URL po dekódování speciálních znaků: https://www.aff.example.com/visit?url=https://www.somestore.com/
  3. Webové stránky, které chcete navštívit: https://www.somestore.com

To clean the URL, we first need to decode special characters (like %3A:, %2F/, etc.) and extract the real URL from the tracking parameters. We will use the $urltransform modifier to do this. The following 4 rules replace URL-encoded symbols with their real characters:

/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%3A/:/ /^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%2F/\// /^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%3F/?/ /^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%3D/=/ /^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/%26/&/

After that, we need to write the rule that will block the tracking website and redirect you directly to the target address (somestore.com):

/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com\/visit\?url=/$urltransform=/^https?:\/\/(?:[a-z0-9-]+\.)*?aff\.example\.com.*url=([^&]*).*/\$1/

Tracking links will now be automatically cleaned up, allowing direct navigation to the destination website without tracking.

Omezení

Rules with the $urltransform modifier can only be used in trusted filters.

Kompatibilita

Rules with the $urltransform modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.15 or later.

noop

noop modifier does nothing and can be used solely to increase rules' readability. It consists of a sequence of underscore characters (_) of arbitrary length and can appear in a rule as often as needed.

Příklady

||example.com$_,removeparam=/^ss\\$/,_,image
||example.com$replace=/bad/good/,___,~third-party
Kompatibilita

Rules with noop modifier are not supported by AdGuard Content Blocker.

$empty (zastaralé)

Deprecation notice

This modifier is deprecated in favor of the $redirect modifier. Rules with $empty are still supported and being converted into $redirect=nooptext now but the support shall be removed in the future.

Usually, blocked requests look like a server error to browser. If you use $empty modifier, AdGuard will emulate a blank response from the server with200 OK status.

Příklady

  • ||example.org^$empty vrátí prázdnou odpověď na všechny požadavky na example.org a všechny subdomény.
Kompatibilita

Rules with $empty modifier are not supported by AdGuard Content Blocker, AdGuard for iOS, and AdGuard for Safari.

$mp4 (zastaralé)

Deprecation notice

This modifier is deprecated in favor of the $redirect modifier. Rules with $mp4 are still supported and being converted into $redirect=noopmp4-1s,media now but the support shall be removed in the future.

As a response to blocked request AdGuard returns a short video placeholder.

Příklady

  • ||example.com/videa/$mp4 zablokuje všechna stahování videa z ||example.com/videa/* a změní odpověď na zástupný videoklip.
Kompatibilita

Rules with $mp4 modifier are not supported by AdGuard Content Blocker, AdGuard for iOS, and AdGuard for Safari.

Priority pravidel

Each rule has its own priority, which is necessary when several rules match the request and the filtering engine needs to select one of them. Priority is measured by a positive integer.

Collisions

When two rules with the same priority match the same request, the filter engine implementation determines which one is chosen.

informace

The concept of rule priorities becomes increasingly important in light of Manifest V3, as the existing rules need to be converted to declarativeNetRequest rules.

Výpočet priority

To calculate priority, we've categorized modifiers into different groups. These groups are ranked based on their priority, from lowest to highest. A modifier that significantly narrows the scope of a rule adds more weight to its total priority. Conversely, if a rule applies to a broader range of requests, its priority decreases.

It's worth noting that there are cases where a single-parameter modifier has a higher priority than multi-parameter ones. For instance, in the case of $domain=example.com|example.org, a rule that includes two domains has a slightly broader effective area than a rule with one specified domain, therefore its priority is lower.

The base priority of any rule is 1. If the calculated priority is a floating-point number, it will be rounded up to the smallest integer greater than or equal to the calculated priority.

Kompatibilita
  • The concept of priority has been introduced in TSUrlFilter v2.1.0 and CoreLibs v1.13. Dříve neměl AdGuard žádný speciální algoritmus pro výpočet priorit a zpracování kolizí se mohlo lišit v závislosti na produktu a verzi AdGuardu.
  • Aplikace AdGuard pro iOS, Safari a Blokátor obsahu AdGuard se spoléhají na implementaci prohlížečů a nemohou dodržovat zde uvedená pravidla.
poznámka

Modifier aliases (1p, 3p, etc.) are not included in these categories, however, they are utilized within the engine to compute the rule priority.

Základní modifikátory, přítomnost každého z nich přidává 1 k prioritě

When dealing with a negated domain, app, method, or content-type, we add 1 point for the existence of the modifier itself, regardless of the quantity of negated domains or content-types. This is because the rule's scope is already infinitely broad. Put simply, by prohibiting multiple domains, content-types, methods or apps, the scope of the rule becomes only minimally smaller.

Definované modifikátory typu obsahu, definované metody, definovaná záhlaví, $all, $popup, specifické výjimky

All valid content types:

This also includes rules that implicitly add all content types:

Or rules that implicitly add the modifier $document:

Or some specific exceptions that implicitly add $document,subdocument:

Or allowed methods via $method.

Or rules with $header.

The presence of any content-type modifiers adds (50 + 50 / N), where N is the number of modifiers present, for example: ||example.com^$image,script will add 50 + 50 / 2 = 50 + 25 = 75 to the total weight of the rule.

The $all also belongs to this category, because it implicitly adds all content-type modifiers, e.g., $document,subdocument,image,script,media,<etc> + $popup.

The $popup also belongs to this category, because it implicitly adds the modifier $document. Similarly, specific exceptions add $document,subdocument.

If there is a $method modifier in the rule with allowed methods it adds (50 + 50 / N), where N is the number of methods allowed, for example: ||example.com^$method=GET|POST|PUT will add 50 + 50 / 3 = 50 + 16.6 = 67 to the total weight of the rule.

If there is a $header modifier in the rule, it adds 50.

$domain nebo $app s povolenými doménami nebo aplikacemi

Specified domains through $domain or specified applications through $app add 100 + 100 / N, where N is the number of modifier values for example: ||example.com^$domain=example.com|example.org|example.net will add 100 + 100 / 3 = 134.3 = 135 or ||example.com^$app=org.example.app1|org.example.app2 will add 100 + 100 / 2 = 151 or ||example.com^$domain=example.com,app=org.example.app1|org.example.app2 will add 100 + 100/1 ($domain part) and 100 + 100/2 ($app part), totaling 350.

Modifier values that are regexps or tld will be interpreted as normal entries of the form example.com and counted one by one, for example: ||example.com^$domain=example.* will add 100 + 100 / 1 = 200 or ||example.com^$domain=example.*|adguard.* will add 100 + 100 / 2 = 150.

Pravidla $redirect

Each of which adds 10^3 to rule priority.

Specifické výjimky

Each of which adds 10^4 to the priority.

As well as exception with $document modifier: because it's an alias for $elemhide,content,jsinject,urlblock,extension. It will add 10^4 for each modifier from the top list, 10^4 * 5 in total.

In addition, each of these exceptions implicitly adds the two allowed content-type modifiers $document,subdocument.

Pravidla seznamu povolených

Modifier @@ adds 10^5 to rule priority.

Pravidla $important

Modifier $important adds 10^6 to rule priority.

Pravidla, pro která není stanovena váha priority

Other modifiers, which are supposed to perform additional post- or pre-processing of requests, do not add anything to the rule priority.

poznámka

The $replace modifier takes precedence over all blocking rules of categories 1–3, as well as exception rules from categories 3–5, except $content, because an exception with the $content modifier overrides all $replace rules.

Příklady

  1. ||example.com^

    Váha pravidla bez modifikátorů: 1.

  2. ||example.com^$match-case

    Váha pravidla: základní + váha modifikátoru z kategorie 1: 1 + 1 = 2.

  3. ||example.org^$removeparam=p

    Váha pravidla: základní váha + 0, protože $removeparam není zahrnuto do výpočtu priority: 1 + 0 = 1.

  4. ||example.org^$document,redirect=nooptext

    Váha pravidla: základní + povolený typ obsahu, kategorie 3 + $redirect z kategorie 6: 1 + (100 + 100 / 1) + 1000 = 1201.

  5. @@||example.org^$removeparam=p,document

    Váha pravidla: základní váha + pravidlo seznamu povolených kategorie 5 + 0, protože $removeparam není zapojeno do výpočtu priority + povolený typ obsahu kategorie 2: 1 + 10000 + 0 + (50 + 50 / 1) = 10101.

  6. @@||example.com/ad/*$domain=example.org|example.net,important

    Váha pravidla: základní váha + pravidlo seznamu povolených kategorie 5 + důležité pravidlo kategorie 7 + povolené domény kategorie 3: 1 + 10000 + 1000000 + (100 + 100 / 2) = 1010152.

  7. @@||example.org^$document bez dalších modifikátorů je aliasem pro @@||example.com^$elemhide,content,jsinject,urlblock,extension

    Váha pravidla: základní váha + specifické výjimky, kategorie 4 + dva povolené typy obsahu (dokument a subdokument) kategorie 2: 1 + 10000 * 4 + (50 + 50 / 2) = 40076.

  8. *$script,domain=a.com,denyallow=x.com|y.com

    Váha pravidla: základní váha + povolený typ obsahu kategorie 2 + povolená doména, kategorie 3 + denyallow kategorie 1: 1 + (50 + 50/1) + (100 + 100 / 1) + 1 = 303.

  9. ||example.com^$all — alias na ||example.com^$document,subdocument,image,script,media,etc. + $popup

    Váha pravidla: základní váha + vyskakovací okno (kategorie 1) + povolené typy obsahu (kategorie 2): 1 + 1 + (50 + 50/12) = 55.

Ostatní pravidla

However, basic rules may not be enough to block ads. Sometimes you need to hide an element or change part of the HTML code of a web page without breaking anything. The rules described in this section are created specifically for this purpose.

Kategorie \ ProduktyAplikace CoreLibsAdGuard pro ChromiumAdGuard pro Chrome MV3AdGuard pro FirefoxAdGuard pro iOSAdGuard pro SafariBlokátor obsahu AdGuard
Skrytí prvků
Pravidla CSS
Rozšířené CSS
HTML filtrování
JavaScript
Scriptlety
poznámka
  • ✅ — plně podporováno
  • ❌ — nepodporováno

Kosmetická pravidla

informace

Work with non-basic rules requires the basic knowledge of HTML and CSS. So, if you want to learn how to make such rules, we recommend to get acquainted with this documentation.

Pravidla pro skrytí prvků

Element hiding rules are used to hide the elements of web pages. It is similar to applying { display: none; } style to selected element.

Element hiding rules may operate differently depending on the platform.

Syntax

   rule = [domains] "##" selector
domains = [domain0, domain1[, ...[, domainN]]]
  • selektorCSS selektor definuje prvky, které mají být skryty.
  • domains — omezení domény pro dané pravidlo.

If you want to limit the rule application area to certain domains, just enter them separated with commas. For example: example.org,example.com##selector.

This rule will be also applied to all subdomains of example.org and example.com.

Pokud chcete, aby se pravidlo nevztahovalo na určité domény, začněte název domény znakem ~. For example: ~example.org##selector.

You can use both approaches in a single rule. For example, example.org,~subdomain.example.org##domain will work for example.org and all subdomains, except subdomain.example.org.

poznámka

Element hiding rules are not dependent on each other. If there is a rule example.org##selector in the filter and you add ~example.org##selector both rules will be applied independently.

Příklady

  • example.com##div.textad — skryje div s třídou textad na doméně example.com a všech subdoménách.
  • example.com,example.org###adblock — skryje prvek s atributem id, který se rovná adblock na example.com, example.org a všech subdoménách.
  • ~example.com##.textad — skryje prvek s třídou textad na všech doménách kromě example.com a jejích subdomén.

Omezení

Safari does not support both allowed and disallowed domains. So the rules like example.org,~foo.example.org##.textad are invalid in AdGuard for Safari.

Výjimky

Exceptions can disable some rules on particular domains. They are very similar to usual exception rules, but instead of ## you have to use #@#.

For example, there is a rule in filter:

##.textad

If you want to disable it for example.com, you can create an exception rule:

example.com#@#.textad

Sometimes, it may be necessary to disable all restriction rules. For example, to conduct tests. To do this, use the exclusion rule without specifying a domain. It will completely disable matching CSS elemhide rule on ALL domains:

#@#.textad

The same can be achieved by adding this rule:

*#@#.textad

We recommend to use this kind of exceptions only if it is not possible to change the hiding rule itself. In other cases it is better to change the original rule, using domain restrictions.

Pravidla CSS

Sometimes, simple hiding of an element is not enough to deal with advertising. For example, blocking an advertising element can just break the page layout. In this case AdGuard can use rules that are much more flexible than hiding rules. With these rules you can basically add any CSS styles to the page.

Syntax

   rule = [domains] "#$#" selector "{" style "}"
domains = [domain0, domain1[, ...[, domainN]]]
  • selektorCSS selektor definuje prvky, na které chceme styl použít.
  • domains — omezení domény pro dané pravidlo. Stejné zásady jako v pravidlech pro skrývání prvků.
  • style — styl CSS, který chceme použít na vybrané prvky.

Příklady

example.com#$#body { background-color: #333!important; }

This rule will apply a style background-color: #333!important; to the body element at example.com and all subdomains.

Výjimky

Just like with element hiding, there is a type of rules that disable the selected CSS style rule for particular domains. Exception rule syntax is almost the same, you just have to change #$# to #@$#.

For example, there is a rule in filter:

#$#.textad { visibility: hidden; }

If you want to disable it for example.com, you can create an exception rule:

example.com#@$#.textad { visibility: hidden; }

We recommend to use this kind of exceptions only if it is not possible to change the CSS rule itself. In other cases it is better to change the original rule, using domain restrictions.

Omezení

Styles that lead to loading any resource are forbidden. Basically, it means that you cannot use any <url> type of value in the style.

Kompatibilita

CSS rules are not supported by AdGuard Content Blocker.

CSS rules may operate differently depending on the platform.

Rozšířené CSS selektory

CSS 3.0 is not always enough to block ads. To solve this problem AdGuard extends CSS capabilities by adding support for the new pseudo-elements. We have developed a separate open-source library for non-standard element selecting and applying CSS styles with extended properties.

The idea of extended capabilities is an opportunity to match DOM elements with selectors based on their own representation (style, text content, etc.) or relations with other elements. There is also an opportunity to apply styles with non-standard CSS properties.

Application area

Extended selectors can be used in any cosmetic rule, whether they are element hiding rules or CSS rules.

Kompatibilita

Rules with extended CSS selectors are not supported by AdGuard Content Blocker.

Syntax

Regardless of the CSS pseudo-classes you are using in the rule, you can use special markers to force applying these rules by ExtendedCss. It is recommended to use these markers for all extended CSS cosmetic rules so that it was easier to find them.

The syntax for extended CSS rules:

  • #?# — pro skrytí prvku, #@?# — pro výjimky
  • #$?# — pro pravidlo CSS, #@$?# — pro výjimky

We strongly recommend using these markers any time when you use an extended CSS selector.

Příklady

  • example.org#?#div:has(> a[target="_blank"][rel="nofollow"]) — toto pravidlo blokuje všechny prvky div obsahující podřízený uzel, který má odkaz s atributy [target="_blank"][rel="nofollow"]. Pravidlo platí pouze pro example.org a její subdomény.
  • example.com#$?#h3:contains(cookies) { display: none!important; } — toto pravidlo nastaví styl display: none!important všem prvkům h3, které obsahují slovo cookies. Pravidlo platí pouze pro example.com a všechny její subdomény.
  • example.net#?#.banner:matches-css(width: 360px) — toto pravidlo blokuje všechny prvky .banner s vlastností stylu width: 360px. Pravidlo platí pouze pro example.net a její subdomény.
  • example.net#@?#.banner:matches-css(width: 360px) — toto pravidlo zakáže předchozí pravidlo.

You can apply standard CSS selectors using the ExtendedCss library by using the rule marker #?#, e.g. #?#div.banner.

Learn more about how to debug extended selectors.

poznámka

Some pseudo-classes do not require selector before it. Still adding the universal selector * makes an extended selector easier to read, even though it has no effect on the matching behavior. So selector #block :has(> .inner) works exactly like #block *:has(> .inner), but the second one is more obvious.

Pseudo-class names are case-insensitive, e.g. :HAS() works as :has(). Still the lower-case names are used commonly.

Limitace ExtendedCss

  1. CSS komentáře a at-pravidla nejsou podporovány.

  2. Konkrétní pseudot-řída může mít svá vlastní omezení: :has(), :xpath(), :nth-ancestor(), :upward(), :is(), :not() a :remove().

Pseudo-třída :has()

Draft CSS 4.0 specification describes the :has() pseudo-class. Unfortunately, it is not yet supported by all popular browsers.

poznámka

Rules with the :has() pseudo-class must use the native implementation of :has() if they use the ## rule marker and if it is possible, i.e., there are no other extended CSS selectors inside. If it is not supported by the product, ExtendedCss implementation will be used even for rules with the ## marker.

Currently, not all AdGuard products support the native implementation of :has() yet:

  • AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux do support it with CoreLibs v1.12 or later.
  • AdGuard for iOS and AdGuard for Safari do support it with SafariConverterLib v2.0.39 and Safari browser v16.4.
  • AdGuard Browser Extension does not support it yet, but it is planned.

To force the ExtendedCss implementation of :has() to be used, use the #?# or #$?# rule markers explicitly, e.g., example.com#?#p:has(> a) or example.com#$?#div:has(> span) { display: none !important; }.

Compatibility with other pseudo-classes

Synonyms :-abp-has() is supported by ExtendedCss for better compatibility.

Removal notice

:if() is no longer supported as a synonym for :has().

Syntax

[target]:has(selector)
  • target — optional, standard or extended CSS selector, can be skipped for checking any element
  • selector — required, standard or extended CSS selector

The pseudo-class :has() selects the target elements that fit to the selector. Also the selector can start with a combinator.

A selector list can be set in selector as well. In this case all selectors in the list are being matched for now. In the future it will be fixed for <forgiving-relative-selector-list> as argument.

:has() limitations

Usage of the :has() pseudo-class is restricted for some cases (2, 3):

  • disallow :has() inside the pseudos accepting only compound selectors;
  • disallow :has() after regular pseudo-elements.

Native :has() pseudo-class does not allow :has(), :is(), :where() inside :has() argument to avoid increasing the :has() invalidation complexity (case 1). But ExtendedCss did not have such limitation earlier and filter lists already contain such rules, so we have not added this limitation to ExtendedCss and allow to use :has() inside :has() as it was possible before. To use it, just force ExtendedCss usage by setting #?#/#$?# rule marker.

Native implementation does not allow any usage of :scope inside the :has() argument ([1], [2]). Still, there are some such rules in filter lists: div:has(:scope a) which we continue to support by simply converting them to div:has(> a), as it used to be done previously.

Příklady

div:has(.banner) selects all div elements which include an element with the banner class:

<!-- HTML code -->
<div>Not selected</div>
<div>Selected
<span class="banner">inner element</span>
</div>

div:has(> .banner) selects all div elements which include an banner class element as a direct child of div:

<!-- HTML code -->
<div>Not selected</div>
<div>Selected
<p class="banner">child element</p>
</div>

div:has(+ .banner) selects all div elements preceding banner class element which immediately follows the div and both are children of the same parent:

<!-- HTML code -->
<div>Not selected</div>
<div>Selected</div>
<p class="banner">adjacent sibling</p>
<span>Not selected</span>

div:has(~ .banner) selects all div elements preceding banner class element which follows the div but not necessarily immediately and both are children of the same parent:

<!-- HTML code -->
<div>Not selected</div>
<div>Selected</div>
<span>Not selected</span>
<p class="banner">general sibling</p>

div:has(span, .banner) selects all div elements which include both span element and banner class element:

<!-- HTML code -->
<div>Not selected</div>
<div>Selected
<span>child span</span>
<p class="banner">child .banner</p>
</div>
Old syntax

Backward compatible syntax for :has() is supported but not recommended.

Pseudo-třída :contains()

The :contains() pseudo-class principle is very simple: it allows to select the elements that contain specified text or which content matches a specified regular expression. Regexp flags are supported.

poznámka

The :contains() pseudo-class uses the textContent element property for matching, not the innerHTML.

Compatibility with other pseudo-classes

Synonyms :-abp-contains() and :has-text() are supported for better compatibility.

Syntax

[target]:contains(match)
  • target — optional, standard or extended CSS selector, can be skipped for checking any element
  • match — required, string or regular expression for matching element textContent. Regular expression flags are supported.

Příklady

For such DOM:

<!-- HTML code -->
<div>Not selected</div>
<div id="match">Selected as IT contains "banner"</div>
<div>Not selected <div class="banner"></div></div>

the element div#match can be selected by any of these extended selectors:

! prostý text
div:contains(banner)

! regulární výraz
div:contains(/as .*banner/)

! regulární výraz s příznaky
div:contains(/it .*banner/gi)
poznámka

Only the div with id=match is selected because the next element does not contain any text, and banner is a part of code, not a text.

Old syntax

Backward compatible syntax for :contains() is supported but not recommended.

Pseudo-třída :matches-css()

The :matches-css() pseudo-class allows to match the element by its current style properties. The work of the pseudo-class is based on using the Window.getComputedStyle() method.

Syntax

[target]:matches-css([pseudo-element, ] property: pattern)
  • target — optional, standard or extended CSS selector, can be skipped for checking any element
  • pseudo-element — optional, valid standard pseudo-element, e.g. before, after, first-line, etc.
  • property — required, a name of CSS property to check the element for
  • pattern — required, a value pattern that is using the same simple wildcard matching as in the basic URL filtering rules or a regular expression. For this type of matching, AdGuard always does matching in a case-insensitive manner. In the case of a regular expression, the pattern looks like /regexp/.

Special characters escaping and unescaping

For non-regexp patterns (,),[,] must be unescaped, e.g. :matches-css(background-image:url(data:*)).

For regexp patterns \ should be escaped, e.g. :matches-css(background-image: /^url\\("data:image\\/gif;base64.+/).

Příklady

For such DOM:

<!-- HTML code -->
<style type="text/css">
#matched::before {
content: "Block me"
}
</style>
<div id="matched"></div>
<div id="not-matched"></div>

the div elements with pseudo-element ::before and with specified content property can be selected by any of these extended selectors:

! string pattern
div:matches-css(before, content: block me)

! string pattern with wildcard
div:matches-css(before, content: block*)

! regular expression pattern
div:matches-css(before, content: /block me/)
Omezení

Regexp patterns do not support flags.

Kompatibilita

Obsolete pseudo-classes :matches-css-before() and :matches-css-after() are no longer recommended but still are supported for better compatibility.

Old syntax

Backward compatible syntax for :matches-css() is supported but not recommended.

Pseudo-třída :matches-attr()

The :matches-attr() pseudo-class allows selecting an element by its attributes, especially if they are randomized.

Syntax

[target]:matches-attr("name"[="value"])
  • target — optional, standard or extended CSS selector, can be skipped for checking any element
  • name — required, simple string or string with wildcard or regular expression for attribute name matching
  • value — optional, simple string or string with wildcard or regular expression for attribute value matching

Escaping special characters

For regexp patterns " and \ should be escaped, e.g. div:matches-attr(class=/[\\w]{5}/).

Příklady

div:matches-attr("ad-link") selects the element div#target1:

<!-- HTML code -->
<div id="target1" ad-link="1random23-banner_240x400"></div>

div:matches-attr("data-*"="adBanner") selects the element div#target2:

<!-- HTML code -->
<div id="target2" data-1random23="adBanner"></div>

div:matches-attr(*unit*=/^click$/) selects the element div#target3:

<!-- HTML code -->
<div id="target3" random123-unit094="click"></div>

*:matches-attr("/.{5,}delay$/"="/^[0-9]*$/") selects the element #target4:

<!-- HTML code -->
<div>
<inner-random23 id="target4" nt4f5be90delay="1000"></inner-random23>
</div>
Omezení

Regexp patterns do not support flags.

Pseudo-třída :matches-property()

The :matches-property() pseudo-class allows selecting an element by matching its properties.

Syntax

[target]:matches-property("name"[="value"])
  • target — optional, standard or extended CSS selector, can be skipped for checking any element
  • name — required, simple string or string with wildcard or regular expression for element property name matching
  • value — optional, simple string or string with wildcard or regular expression for element property value matching

Escaping special characters

For regexp patterns " and \ must be escaped, e.g. div:matches-property(prop=/[\\w]{4}/).

poznámka

Regexp patterns are supported in name for any property in chain, e.g. prop./^unit[\\d]{4}$/.type.

Příklady

An element with such properties:

divProperties = {
id: 1,
check: {
track: true,
unit_2random1: true,
},
memoizedProps: {
key: null,
tag: 12,
_owner: {
effectTag: 1,
src: 'ad.com',
},
},
};

can be selected by any of these extended selectors:

div:matches-property(check.track)

div:matches-property("check./^unit_.{4,8}$/")

div:matches-property("check.unit_*"=true)

div:matches-property(memoizedProps.key="null")

div:matches-property(memoizedProps._owner.src=/ad/)
For filter maintainers

To check properties of a specific element, do the following:

  1. Zkontrolujte prvek stránky nebo jej vyberte na kartě Elements v nástroji DevTools prohlížeče
  2. Spusťte console.dir($0) na kartě Console
Omezení

Regexp patterns do not support flags.

Pseudo-třída :xpath()

The :xpath() pseudo-class allows selecting an element by evaluating an XPath expression.

Syntax

[target]:xpath(expression)
  • target- optional, standard or extended CSS selector
  • expression — required, valid XPath expression
:xpath() limitations

target can be omitted so it is optional. For any other pseudo-class that would mean "apply to all DOM nodes", but in case of :xpath() it just means "apply to the whole document", and such applying slows elements selecting significantly. That's why rules like #?#:xpath(expression) are limited to looking inside the body tag. For example, rule #?#:xpath(//div[@data-st-area=\'Advert\']) is parsed as #?#body:xpath(//div[@data-st-area=\'Advert\']).

Extended selectors with defined target as any selector — *:xpath(expression) — can still be used but it is not recommended, so target should be specified instead.

Works properly only at the end of selector, except for pseudo-class :remove().

Příklady

:xpath(//*[@class="banner"]) selects the element div#target1:

<!-- HTML code -->
<div id="target1" class="banner"></div>

:xpath(//*[@class="inner"]/..) selects the element div#target2:

<!-- HTML code -->
<div id="target2">
<div class="inner"></div>
</div>

Pseudo-třída :nth-ancestor()

The :nth-ancestor() pseudo-class allows to lookup the nth ancestor relative to the previously selected element.

subject:nth-ancestor(n)
  • subject — required, standard or extended CSS selector
  • n — required, number >= 1 and < 256, distance to the needed ancestor from the element selected by subject

Syntax

subject:nth-ancestor(n)
  • subject — required, standard or extended CSS selector
  • n — required, number >= 1 and < 256, distance to the needed ancestor from the element selected by subject
:nth-ancestor() limitations

The :nth-ancestor() pseudo-class is not supported inside the argument of the :not() pseudo-class.

Příklady

For such DOM:

<!-- HTML code -->
<div id="target1">
<div class="child"></div>

<div id="target2">
<div>
<div>
<div class="inner"></div>
</div>
</div>
</div>
</div>

.child:nth-ancestor(1) selects the element div#target1, div[class="inner"]:nth-ancestor(3) selects the element div#target2.

Pseudo-třída :upward()

The :upward() pseudo-class allows to lookup the ancestor relative to the previously selected element.

Syntax

subject:upward(ancestor)
  • subject — required, standard or extended CSS selector
  • ancestor — required, specification for the ancestor of the element selected by subject, can be set as:
    • number >= 1 and < 256 for distance to the needed ancestor, same as :nth-ancestor()
    • standard CSS selector for matching closest ancestor
:upward() limitations

The :upward() pseudo-class is not supported inside the argument of the :not() pseudo-class.

Příklady

For such DOM:

<!-- HTML code -->
<div id="target1" data="true">
<div class="child"></div>

<div id="target2">
<div>
<div>
<div class="inner"></div>
</div>
</div>
</div>
</div>

.inner:upward(div[data]) selects the element div#target1, .inner:upward(div[id]) selects the element div#target2, .child:upward(1) selects the element div#target1, .inner:upward(3) selects the element div#target2.

Pseudo-třída :remove() a pseudo-vlastnost remove

Sometimes, it is necessary to remove a matching element instead of hiding it or applying custom styles. In order to do it, you can use the :remove() pseudo-class as well as the remove pseudo-property.

Pseudo-class :remove() can be placed only at the end of a selector.

Syntax

! pseudo-class
selector:remove()

! pseudo-property
selector { remove: true; }
  • selector — required, standard or extended CSS selector
:remove() a remove limitations

The :remove() pseudo-class is limited to work properly only at the end of selector.

For applying the :remove() pseudo-class to any element, the universal selector * should be used. Otherwise such extended selector may be considered as invalid, e.g. .banner > :remove() is not valid for removing any child element of banner class element, so it should look like .banner > *:remove().

If the :remove() pseudo-class or the remove pseudo-property is used, all style properties are ignored except for the debug pseudo-property.

Příklady

div.banner:remove()
div:has(> div[ad-attr]):remove()

div:contains(advertisement) { remove: true; }
div[class]:has(> a > img) { remove: true; }
poznámka

Rules with the remove pseudo-property must use #$?# marker: $ for CSS-style rule syntax, ? for ExtendedCss syntax.

Pseudo-třída :is()

The :is() pseudo-class allows to match any element that can be selected by any of selectors passed to it. Invalid selectors are skipped and the pseudo-class deals with valid ones with no error thrown. Our implementation of the native :is() pseudo-class.

Syntax

[target]:is(selectors)
  • target — optional, standard or extended CSS selector, can be skipped for checking any element
  • selectorsforgiving selector list of standard or extended selectors. For extended selectors, only compound selectors are supported, not complex.
:is() limitations

Rules with the :is() pseudo-class must use the native implementation of :is() if rules use ## marker and it is possible, i.e. with no other extended selectors inside. To force applying ExtendedCss rules with :is(), use #?#/#$?# marker explicitly.

If the :is() pseudo-class argument selectors is an extended selector, due to the way how the :is() pseudo-class is implemented in ExtendedCss v2.0, it is impossible to apply it to the top DOM node which is html, i.e. #?#html:is(<extended-selectors>) does not work. So if target is not defined or defined as the universal selector *, the extended pseudo-class applying is limited to html's children, e.g. rules #?#:is(...) and #?#*:is(...) are parsed as #?#html *:is(...). Please note that there is no such limitation for a standard selector argument, i.e. #?#html:is(.locked) works fine.

Complex selectors with extended pseudo-classes are not supported as selectors argument for :is() pseudo-class, only compound ones are allowed. Check examples below for more details.

Příklady

#container *:is(.inner, .footer) selects only the element div#target1:

<!-- HTML code -->
<div id="container">
<div data="true">
<div>
<div id="target1" class="inner"></div>
</div>
</div>
</div>

Due to limitations :is(*:not([class]) > .banner)' does not work but :is(*:not([class]):has(> .banner)) can be used instead of it to select the element div#target2:

<!-- HTML code -->
<span class="span">text</span>
<div id="target2">
<p class="banner">inner paragraph</p>
</div>

Pseudo-třída :not()

The :not() pseudo-class allows to select elements which are not matched by selectors passed as argument. Invalid argument selectors are not allowed and error is to be thrown. Our implementation of the :not() pseudo-class.

Syntax

[target]:not(selectors)
  • target — optional, standard or extended CSS selector, can be skipped for checking any element
  • selectors — list of standard or extended selectors
:not() limitations

Rules with the :not() pseudo-class must use the native implementation of :not() if rules use ## marker and it is possible, i.e. with no other extended selectors inside. To force applying ExtendedCss rules with :not(), use #?#/#$?# marker explicitly.

If the :not() pseudo-class argument selectors is an extended selector, due to the way how the :not() pseudo-class is implemented in ExtendedCss v2.0, it is impossible to apply it to the top DOM node which is html, i.e. #?#html:not(<extended-selectors>) does not work. So if target is not defined or defined as the universal selector *, the extended pseudo-class applying is limited to html's children, e.g. rules #?#:not(...) and #?#*:not(...) are parsed as #?#html *:not(...). Please note that there is no such limitation for a standard selector argument, i.e. #?#html:not(.locked) works fine.

The :not() is considered as a standard CSS pseudo-class inside the argument of the :upward() pseudo-class because :upward() supports only standard selectors.

"Up-looking" pseudo-classes which are :nth-ancestor() and :upward() are not supported inside selectors argument for :not() pseudo-class.

Příklady

#container > *:not(h2, .text) selects only the element div#target1:

<!-- HTML code -->
<div id="container">
<h2>Header</h2>
<div id="target1"></div>
<span class="text">text</span>
</div>

Pseudo-třída :if-not() (odstraněno)

Removal notice

The :if-not() pseudo-class is removed and is no longer supported. Rules with it are considered as invalid.

This pseudo-class was basically a shortcut for :not(:has()). It was supported by ExtendedCss for better compatibility with some filters subscriptions.

Přednost kosmetických pravidel

The way element hiding and CSS rules are applied is platform-specific.

In AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux, we use a stylesheet injected into the page. The priority of cosmetic rules is the same as any other websites' CSS stylesheet. But there is a limitation: element hiding and CSS rules cannot override inline styles. In such cases, it is recommended to use extended selectors or HTML filtering.

In AdGuard Browser Extension, the so-called "user stylesheets" are used. They have higher priority than even the inline styles.

Extended CSS selectors use JavaScript to work and basically add an inline style themselves, therefore they can override any style.

HTML pravidla filtrování

In most cases, the basis and cosmetic rules are enough to filter ads. But sometimes it is necessary to change the HTML-code of the page itself before it is loaded. This is when you need filtering rules for HTML content. They allow to indicate the HTML elements to be cut out before the browser loads the page.

Kompatibilita

HTML filtering rules are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, AdGuard for Linux, and AdGuard Browser Extension for Firefox. Such rules do not work in extensions for other browsers because they are unable to modify content on network level.

Syntax

     selector = [tagName] [attributes] [pseudoClasses]
combinator = ">"
rule = [domains] "$$" selector *(combinator selector)
domains = [domain0, domain1[, ...[, domainN]]]
attributes = "[" name0 = value0 "]" "[" name1 = value2 "]" ... "[" nameN = valueN "]"
pseudoClasses = pseudoClass *pseudoClass
pseudoClass = ":" pseudoName [ "(" pseudoArgs ")" ]
  • tagName — name of the element in lower case, for example, div or script.
  • domains — omezení domény pro dané pravidlo. Same principles as in element hiding rule syntax.
  • attributes — a list of attributes that limit the selection of elements. name — attribute name, value — substring, that is contained in attribute value.
  • pseudoName — the name of a pseudo-class.
  • pseudoArgs — the arguments of a function-style pseudo-class.
  • combinator — an operator that works similarly to the CSS child combinator: that is, the selector on the right of the combinator will only match an element whose direct parent matches the selector on the left of the combinator.

Příklady

HTML code:

<script data-src="/banner.js"></script>

Rule:

example.org$$script[data-src="banner"]

This rule removes all script elements with the attribute data-src containing the substring banner. The rule applies only to example.org and all its subdomains.

Speciální atributy

In addition to usual attributes, which value is every element checked for, there is a set of special attributes that change the way a rule works. Below there is a list of these attributes:

tag-content

Deprecation notice

This special attribute may become unsupported in the future. Prefer using the :contains() pseudo-class where it is available.

This is the most frequently used special attribute. It limits selection with those elements whose innerHTML code contains the specified substring.

You must use "" to escape ", for instance: $$script[tag-content="alert(""this is ad"")"]

For example, take a look at this HTML code:

<script type="text/javascript">
document.write('<div>banner text</div>" />');
</script>

Following rule will delete all script elements with a banner substring in their code:

$$script[tag-content="banner"]
Omezení

The tag-content special attribute must not appear in a selector to the left of a > combinator.

wildcard

Deprecation notice

This special attribute may become unsupported in the future. Prefer using the :contains() pseudo-class where it is available.

This special attribute works almost like tag-content and allows you to check the innerHTML code of the document. Rule will check if HTML code of the element fits the search pattern.

You must use "" to escape ", for instance: $$script[wildcard=""banner""]

For example: $$script[wildcard="*banner*text*"]

It checks if the element code contains the two consecutive substrings banner and text.

Omezení

The wildcard special attribute must not appear in a selector to the left of a > combinator.

max-length

Deprecation notice

This special attribute may become unsupported in the future. Prefer using the :contains() pseudo-class with a regular expression where it is available.

Specifies the maximum length for content of HTML element. If this parameter is set and the content length exceeds the value, a rule does not apply to the element.

Default value

If this parameter is not specified, the max-length is considered to be 8192.

Např:

$$div[tag-content="banner"][max-length="400"]

This rule will remove all the div elements, whose code contains the substring banner and the length of which does not exceed 400 characters.

Omezení

The max-length special attribute must not appear in a selector to the left of a > combinator.

min-length

Deprecation notice

This special attribute may become unsupported in the future. Prefer using the :contains() pseudo-class with a regular expression where it is available.

Specifies the minimum length for content of HTML element. If this parameter is set and the content length is less than preset value, a rule does not apply to the element.

Např:

$$div[tag-content="banner"][min-length="400"]

This rule will remove all the div elements, whose code contains the substring banner and the length of which exceeds 400 characters.

Omezení

The min-length special attribute must not appear in a selector to the left of a > combinator.

Pseudotřídy

:contains()

Syntax
:contains(unquoted text)

nebo

:contains(/reg(ular )?ex(pression)?/)
Compatibility

:-abp-contains() and :has-text() are synonyms for :contains().

Kompatibilita

The :contains() pseudo-class is supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.13 or later.

Requires that the inner HTML of the element contains the specified text or matches the specified regular expression.

Omezení

A :contains() pseudo-class must not appear in a selector to the left of a > combinator.

Výjimky

Similar to hiding rules, there is a special type of rules that disable the selected HTML filtering rule for particular domains. The syntax is the same, you just have to change $$ to $@$.

For example, there is a rule in filter:

$$script[tag-content="banner"]

If you want to disable it for example.com, you can create an exception rule:

example.com$@$script[tag-content="banner"]

Sometimes, it may be necessary to disable all restriction rules. For example, to conduct tests. To do this, use the exclusion rule without specifying a domain.

$@$script[tag-content="banner"]

We recommend to use this kind of exceptions only if it is not possible to change the hiding rule itself. In other cases it is better to change the original rule, using domain restrictions.

Pravidla JavaScript

AdGuard supports a special type of rules that allows you to inject any JavaScript code to websites pages.

We strongly recommend using scriptlets instead of JavaScript rules whenever possible. JS rules are supposed to help with debugging, but as a long-time solution a scriptlet rule should be used.

Syntax

rule = [domains] "#%#" script

Příklady

  • example.org#%#window.__gaq = undefined; executes the code window.__gaq = undefined; on all pages at example.org and all subdomains.

Výjimky

Similar to hiding rules, there is a special type of rules that disable the selected JavaScript rule for particular domains. The syntax is the same, you just have to change #%# to #@%#.

For example, there is a rule in filter:

#%#window.__gaq = undefined;

If you want to disable it for example.com, you can create an exception rule:

example.com#@%#window.__gaq = undefined;

Sometimes, it may be necessary to disable all restriction rules. For example, to conduct tests. To do this, use the exclusion rule without specifying a domain.

#@%#window.__gaq = undefined;

We recommend to use this kind of exceptions only if it is not possible to change the hiding rule itself. In other cases it is better to change the original rule, using domain restrictions.

Omezení

JavaScript rules can only be used in trusted filters.

Kompatibilita

JavaScript rules are not supported by AdGuard Content Blocker.

Pravidla skriptlet

Scriptlet is a JavaScript function that provides extended capabilities for content blocking. These functions can be used in a declarative manner in AdGuard filtering rules.

poznámka

AdGuard supports a lot of different scriptlets. In order to achieve cross-blocker compatibility, we also support syntax of uBO and ABP.

Blocking rules syntax

[domains]#%#//scriptlet(name[, arguments])
  • domains — optional, a list of domains where the rule should be applied;
  • name — required, a name of the scriptlet from the AdGuard Scriptlets library;
  • arguments — optional, a list of string arguments (no other types of arguments are supported).

Příklady

  1. Použijte skriptlet abort-on-property-read na všech stránkách example.org a jejích subdoménách a předejte mu argument alert:

    example.org#%#//scriptlet('abort-on-property-read', 'alert')
  2. Odstraňte třídu branding ze všech prvků div[class^="inner"] na všech stránkách example.org a jejích subdoménách:

    example.org#%#//scriptlet('remove-class', 'branding', 'div[class^="inner"]')

Exception rules syntax

Exception rules can disable some scriptlets on particular domains. The syntax for exception scriptlet rules is similar to normal scriptlet rules but uses #@%# instead of #%#:

[domains]#@%#//scriptlet([name[, arguments]])
  • domains — optional, a list of domains where the rule should be applied;
  • name — optional, a name of the scriptlet to except from the applying; if not set, all scriptlets will not be applied;
  • arguments — optional, a list of string arguments to match the same blocking rule and disable it.

Příklady

  1. Zakázat specifické pravidlo skriptletu tak, aby se pouze abort-on-property-read použilo pouze na example.org a její subdomény:

    example.org,example.com#%#//scriptlet("abort-on-property-read", "alert")
    example.com#@%#//scriptlet("abort-on-property-read", "alert")
  2. Zakázat všechny skriptlety abort-on-property-read pro example.com a její subdomény:

    example.org,example.com#%#//scriptlet("abort-on-property-read", "alert")
    example.com#@%#//scriptlet("abort-on-property-read")
  3. Zakázat všechny skriptlety pro example.com a její subdomény:

    example.org,example.com#%#//scriptlet("abort-on-property-read", "alert")
    example.com#@%#//scriptlet()
  4. Použijte set-constant a set-cookie na libovolnou webovou stránku, ale vzhledem ke speciálnímu pravidlu výjimky pro skriplety bude na stránce example.org a jejích subdoménách použito pouze set-constant:

    #%#//scriptlet('set-constant', 'adList', 'emptyArr')
    #%#//scriptlet('set-cookie', 'accepted', 'true')
    example.org#@%#//scriptlet('set-cookie')
  5. Použijte adjust-setInterval na libovolnou webovou stránku a set-local-storage-item na example.com a jejích subdoménách, ale existuje také několik pravidel pro výjimky skriptletů, takže na example.com a jejích subdoménách nebudou použita žádná pravidla pro skriptlety:

    #%#//scriptlet('adjust-setInterval', 'count', '*', '0.001')
    example.com#%#//scriptlet('set-local-storage-item', 'ALLOW_COOKIES', 'false')
    example.com#@%#//scriptlet()

Learn more about how to debug scriptlets.

More information about scriptlets can be found on GitHub.

Kompatibilita

Scriptlet rules are not supported by AdGuard Content Blocker.

The full syntax of scriptlet exception rules is supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.16 or later, and AdGuard Browser Extension for Chrome, Firefox, and Edge with TSUrlFilter v3.0 or later. Previous versions only support exception rules that disable specific scriptlets.

Důvěryhodné skriptlety

Trusted scriptlets are scriptlets with extended functionality. It means the same syntax and restrictions. Trusted scriptlet names are prefixed with trusted-, e.g. trusted-set-cookie, to be easily distinguished from common scriptlets.

poznámka

Trusted scriptlets are not compatible with other ad blockers except AdGuard.

Omezení

Trusted scriptlets rules can only be used in trusted filters.

Kompatibilita

Trusted scriptlets rules are not supported by AdGuard Content Blocker.

Learn more about how to debug scriptlets.

More information about trusted scriptlets can be found on GitHub.

Modifikátory pro ostatní typ pravidel

Each rule can be modified using the modifiers described in the following paragraphs.

Syntax {#non-basic-rules-modifiers-syntax}

rule = "[$" modifiers "]" [rule text]
modifiers = modifier0[, modifier1[, ...[, modifierN]]]
  • modifier — set of the modifiers described below.
  • rule text — a rule to be modified.

For example, [$domain=example.com,app=test_app]##selector.

In the modifiers values, the following characters must be escaped: [, ], ,, and \ (unless it is used for the escaping). Use \ to escape them. For example, an escaped bracket looks like this: \].

Modifikátor \ ProduktyAplikace CoreLibsAdGuard pro ChromiumAdGuard pro Chrome MV3AdGuard pro FirefoxAdGuard pro iOSAdGuard pro SafariBlokátor obsahu AdGuard
$app
$domain*[1]
$path
$url*[2]*[2]*[2]
poznámka
  • ✅ — plně podporováno
  • ✅ * — podporováno, ale spolehlivost se může lišit nebo se mohou vyskytnout omezení; více informací naleznete v popisu modifikátoru
  • ❌ — nepodporováno

$app

$app modifier lets you narrow the rule coverage down to a specific application or a list of applications. The modifier's behavior and syntax perfectly match the corresponding basic rules $app modifier.

Příklady

  • [$app=org.example.app]example.com##.textad hides a div with the class textad at example.com and all subdomains in requests sent from the org.example.app Android app.
  • [$app=~org.example.app1|~org.example.app2]example.com##.textad hides a div with the class textad at example.com and all subdomains in requests sent from any app except org.example.app1 and org.example.app2.
  • [$app=com.apple.Safari]example.org#%#//scriptlet('prevent-setInterval', 'check', '!300') applies scriptlet prevent-setInterval only in Safari browser on Mac.
  • [$app=org.example.app]#@#.textad disables all ##.textad rules for all domains while using org.example.app.
Kompatibilita

Such rules with $app modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux.

$domain

$domain modifier limits the rule application area to a list of domains and their subdomains. The modifier's behavior and syntax perfectly match the corresponding basic rules $domain modifier.

Příklady

  • [$domain=example.com]##.textad — hides a div with the class textad at example.com and all subdomains.
  • [$domain=example.com|example.org]###adblock — hides an element with attribute id equals adblock at example.com, example.org and all subdomains.
  • [$domain=~example.com]##.textad — this rule hides div elements of the class textad for all domains, except example.com and its subdomains.

There are 2 ways to specify domain restrictions for non-basic rules:

  1. "klasický" způsob je zadat domény před masku pravidla a atributy: example.com##.textad;
  2. přístup modifikátoru spočívá v určení domén pomocí modifikátoru $domain: [$domain=example.com]##.textad.

But rules with mixed style domains restriction are considered invalid. So, for example, the rule [$domain=example.org]example.com##.textad will be ignored.

Nezákladní omezení modifikátoru $domain

Omezení

Since the non-basic $domain works the same as the basic one, it has the same limitations.

Kompatibilita

Such rules with $domain modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, AdGuard Browser Extension for Chrome, Chrome MV3, Firefox, and Edge.

$path

$path modifier limits the rule application area to specific locations or pages on websites.

Syntax

$path ["=" pattern]

pattern — optional, a path mask to which the rule is restricted. Its syntax and behavior are pretty much the same as with the pattern for basic rules. You can also use special characters, except for ||, which does not make any sense in this case (see examples below).

If pattern is not set for $path, rule will apply only on the main page of website.

$path modifier matches the query string as well.

$path modifier supports regular expressions in the same way basic rules do.

Příklady

  • [$path=page.html]##.textad hides a div with the class textad at /page.html or /page.html?<query> or /sub/page.html or /another_page.html
  • [$path=/page.html]##.textad hides a div with the class textad at /page.html or /page.html?<query> or /sub/page.html of any domain but not at /another_page.html
  • [$path=|/page.html]##.textad hides a div with the class textad at /page.html or /page.html?<query> of any domain but not at /sub/page.html
  • [$path=/page.html|]##.textad hides a div with the class textad at /page.html or /sub/page.html of any domain but not at /page.html?<query>
  • [$path=/page*.html]example.com##.textad hides a div with the class textad at /page1.html or /page2.html or any other path matching /page<...>.html of example.com
  • [$path]example.com##.textad hides a div with the class textad at the main page of example.com
  • [$domain=example.com,path=/page.html]##.textad hides a div with the class textad at page.html of example.com and all subdomains but not at another_page.html
  • [$path=/\\/(sub1|sub2)\\/page\\.html/]##.textad hides a div with the class textad at both /sub1/page.html and /sub2/page.html of any domain (please note the escaped special characters)
Kompatibilita

Rules with $path modifier are not supported by AdGuard Content Blocker.

$url

$url modifier limits the rule application area to URLs matching the specified mask.

Syntax

url = pattern

where pattern is pretty much the same as pattern of the basic rules assuming that some characters must be escaped. The special characters and regular expressions are supported as well.

Příklady

  • [$url=||example.com/content/*]##div.textad hides a div with the class textad at addresses like https://example.com/content/article.html and even https://subdomain.example.com/content/article.html.
  • [$url=||example.org^]###adblock hides an element with attribute id equal to adblock at example.org and its subdomains.
  • [$url=/\[a-z\]+\\.example\\.com^/]##.textad hides div elements of the class textad for all domains matching the regular expression [a-z]+\.example\.com^.

omezení modifikátoru $url

Omezení

In AdGuard Browser Extension, non-basic $url modifier is not compatible with domain-specific rules and other non-basic modifiers — $domain and $path. For example, the rule [$url=/category/*]example.com###textad will not be applied.

Kompatibilita

Rules with the $url modifier are supported by AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux with CoreLibs v1.11 or later, and AdGuard Browser Extension with TSUrlFilter v3.0.0 or later.

Informace pro správce filtrů

If you maintain a third-party filter that is known to AdGuard, you might be interested in the information presented in this section. Please note that hints will be applied to registered filters only. The filter is considered to be registered and known by AdGuard, if it is present in the known filters index. If you want your filter to be registered, please file an issue to AdguardFilters repo.

Direktivy preprocesoru

We provide preprocessor directives that can be used by filter maintainers to improve compatibility with different ad blockers and provide:

poznámka

Any mistake in a preprocessor directive will lead to AdGuard failing the filter update in the same way as if the filter URL was unavailable.

Preprocessor directives can be used in the user rules or in the custom filters.

Zahrnutý soubor

The !#include directive allows to include contents of a specified file into the filter. It supports only files from the same origin to make sure that the filter maintainer is in control of the specified file. The included file can also contain pre-directives (even other !#include directives). Ad blockers should consider the case of recursive !#include and implement a protection mechanism.

Syntax

!#include file_path

where file_path is a same origin absolute or relative file path to be included.

The files must originate from the same domain, but may be located in a different folder.

If included file is not found or unavailable, the whole filter update should fail.

Same-origin limitation should be disabled for local custom filters.

Příklady

Filter URL: https://example.org/path/filter.txt

! Valid (same origin):
!#include https://example.org/path/includedfile.txt
!
! Valid (relative path):
!#include /includedfile.txt
!#include ../path2/includedfile.txt
!
! Invalid (another origin):
!#include https://domain.com/path/includedfile.txt

Podmínky

Filter maintainers can use conditions to supply different rules depending on the ad blocker type. A conditional directive beginning with an !#if directive must explicitly be terminated with an !#endif directive. Conditions support all basic logical operators.

There are two possible scenarios:

  1. Pokud blokátor reklamy narazí na direktivu !#if a ne !#else, zkompiluje kód mezi direktivami !#if a !#endif pouze v případě, že je zadaná podmínka pravdivá.

  2. Pokud existuje direktiva !#else, bude zkompilován kód mezi !#if a !#else, pokud je podmínka pravdivá; v opačném případě bude zkompilován kód mezi !#else a !#endif.

poznámka

Whitespaces matter. !#if is a valid directive, while !# if is not.

Syntax

!#if (conditions)
rules_list
!#endif

nebo

!#if (conditions)
true_conditions_rules_list
!#else
false_conditions_rules_list
!#endif

where:

  • !#if (conditions) — start of the block when conditions are true
  • conditions — just like in some popular programming languages, preprocessor conditions are based on constants declared by ad blockers. Authors of ad blockers define on their own what exact constants they declare. Possible values:
    • adguard always declared; shows maintainers that this is one of AdGuard products; should be enough in 95% of cases
    • product-specific constants for cases when you need a rule to work (or not work — then ! should be used before constant) in a specific product only:
      • adguard_app_windows — AdGuard for Windows
      • adguard_app_mac — AdGuard for Mac
      • adguard_app_cli — AdGuard for Linux
      • adguard_app_android — AdGuard for Android
      • adguard_app_ios — AdGuard for iOS
      • adguard_ext_safari — AdGuard for Safari
      • adguard_ext_chromium — AdGuard Browser Extension for Chrome (and chromium-based browsers, e.g. new Microsoft Edge)
      • adguard_ext_chromium_mv3AdGuard for Chrome MV3
      • adguard_ext_firefox — AdGuard Browser Extension for Firefox
      • adguard_ext_edge — AdGuard Browser Extension for Edge Legacy
      • adguard_ext_opera — AdGuard Browser Extension for Opera
      • adguard_ext_android_cb — AdGuard Content Blocker for mobile Samsung and Yandex browsers
      • ext_ublock — special case; this one is declared when a uBlock version of a filter is compiled by the FiltersRegistry
      • cap_html_filtering — products that support HTML filtering rules: AdGuard for Windows, AdGuard for Mac, AdGuard for Android, and AdGuard for Linux
  • !#else — start of the block when conditions are false
  • rules_list, true_conditions_rules_list, false_conditions_rules_list — lists of rules
  • !#endif — end of the block

Příklady

! for all AdGuard products except AdGuard for Safari
!#if (adguard && !adguard_ext_safari)
||example.org^$third-party
domain.com##div.ad
!#endif
! directives even can be combined
!#if (adguard_app_android)
!#include /androidspecific.txt
!#endif
!#if (adguard && !adguard_ext_safari)
! pro všechny produkty AdGuardu kromě AdGuardu pro Safari
||example.org^$third-party
domain.com##div.ad
!#else
! pouze pro AdGuard pro Safari
||subdomena.example.org^$third-party
!#endif
Kompatibilita

The !#else directive is supported by the FiltersDownloader v1.1.20 or later.

It is already supported for filter lists compiled by the FiltersRegistry, but it still may not be supported by AdGuard products when adding a filter list with !#else as a custom one. The following products will support it in the mentioned versions or later:

  • AdGuard for Windows, Mac, and Android with CoreLibs v1.13;
  • AdGuard Browser Extension v4.2.208;
  • AdGuard v1.11.16 for Safari.

Afinita Safari

Safari's limit for each content blocker is 150,000 active rules. But in AdGuard for Safari and AdGuard for iOS, we've split the rules into 6 content blockers, thus increasing the rule limit to 900,000.

Here is the composition of each content blocker:

  • AdGuard General — Ad Blocking, Language-specific
  • AdGuard Privacy — Privacy
  • AdGuard Social — Social Widgets, Annoyances
  • AdGuard Security — Security
  • AdGuard Other — Other
  • AdGuard Custom — Custom

User rules and allowlist are added to every content blocker.

pozor

The main disadvantage of using multiple content blockers is that rules from different blockers are applied independently. Blocking rules are not affected by this, but unblocking rules may cause problems. If a blocking rule is in one content blocker and an exception is in another, the exception will not work. Filter maintainers use !#safari_cb_affinity to define Safari content blocker affinity for the rules inside of the directive block.

Syntax

!#safari_cb_affinity(content_blockers)
rules_list
!#safari_cb_affinity

where:

  • !#safari_cb_affinity(content_blockers) — start of the block
  • content_blockers — comma-separated list of content blockers. Possible values:
    • general — AdGuard General content blocker
    • privacy — AdGuard Privacy content blocker
    • social — AdGuard Social content blocker
    • security — AdGuard Security content blocker
    • other — AdGuard Other content blocker
    • custom — AdGuard Custom content blocker
    • all — special keyword that means that the rules must be included into all content blockers
  • rules_list — list of rules
  • !#safari_cb_affinity — end of the block

Příklady

! to unhide specific element which is hidden by AdGuard Base filter:
!#safari_cb_affinity(general)
example.org#@#.adBanner
!#safari_cb_affinity
! to allowlist basic rule from AdGuard Tracking Protection filter:
!#safari_cb_affinity(privacy)
@@||example.org^
!#safari_cb_affinity

Nápovědy

"Hint" is a special comment, instruction to the filters compiler used on the server side (see FiltersRegistry).

Syntax

!+ HINT_NAME1(PARAMS) HINT_NAME2(PARAMS)

Multiple hints can be applied.

Nápověda NOT_OPTIMIZED

For each filter, AdGuard compiles two versions: full and optimized. Optimized version is much more lightweight and does not contain rules which are not used at all or used rarely.

Rules usage frequency comes from the collected filter rules statistics. But filters optimization is based on more than that — some filters have specific configuration. This is how it looks like for Base filter:

"filter": AdGuard Base filter,
"percent": 30,
"minPercent": 20,
"maxPercent": 40,
"strict": true

where:

  • filter — filter identifier
  • percent — expected optimization percent ~= (rules count in optimized filter) / (rules count in original filter) * 100
  • minPercent — lower bound of percent value
  • maxPercent — upper bound of percent value
  • strict — if percent < minPercent OR percent > maxPercent and strict mode is on then filter compilation should fail, otherwise original rules must be used

In other words, percent is the "compression level". For instance, for the Base filter it is configured to 40%. It means that optimization algorithm should strip 60% of rules.

Eventually, here are the two versions of the Base filter for AdGuard Browser Extension:

If you want to add a rule which should not be removed at optimization use the NOT_OPTIMIZED hint:

!+ NOT_OPTIMIZED
||example.org^

And this rule will not be optimized only for AdGuard for Android:

!+ NOT_OPTIMIZED PLATFORM(android)
||example.org^

Nápověda PLATFORM a NOT_PLATFORM

Used to specify the platforms to apply the rules. List of existing platforms and links to Base filter, for example, for each of them:

Příklady

This rule will be available only in AdGuard for Windows, Mac, Android:

!+ PLATFORM(windows,mac,android)
||example.org^

Except for AdGuard for Safari, AdGuard Content Blocker, and AdGuard for iOS, this rule is available on all platforms:

!+ NOT_PLATFORM(ext_safari, ext_android_cb, ios)
||example.org^

NOT_VALIDATE

This hint is used to skip validation of the rule. It is useful for rules for which support has not yet been added to the filters compiler, or for rules that are incorrectly discarded.

If you want to add a rule that should not be validated, use the NOT_VALIDATE hint:

!+ NOT_VALIDATE
||example.org^$newmodifier

Jak ladit pravidla filtrování

It may be possible to create simple filtering rules "in your head" but for anything even slightly more complicated you will need additional tools to debug and iterate them. There are tools to assist you with that. You can use DevTools in Chrome and its analogs in other browsers but most AdGuard products provide another one — Filtering log.

Záznam filtrování

Filtering log is an advanced tool that will be helpful mostly to filter developers. It lists all web requests that pass through AdGuard, gives you exhaustive information on each of them, offers multiple sorting options, and has other useful features.

Depending on which AdGuard product you are using, Filtering log can be located in different places.

  • In AdGuard for Windows, you can find it in the Ad Blocker tab or via the tray menu
  • In AdGuard for Mac, it is located in Settings → Advanced → Filtering log
  • In AdGuard for Android, you can find it under Statistics → Recent activity. Recent activity can also be accessed from the Assistant
  • In AdGuard Browser Extension, it is accessible from the Miscellaneous settings tab or by right-clicking the extension icon. Only Chromium- and Firefox-based web browsers show applied element hiding rules (including CSS, ExtCSS) and JS rules and scriptlets in their Filtering logs
poznámka

In AdGuard for iOS and AdGuard for Safari, Filtering log does not exist because of the way content blockers are implemented in Safari. AdGuard does not see the web requests and therefore cannot display them.

Režim ladění selektorů

Sometimes, you might need to check the performance of a given selector or a stylesheet. In order to do it without interacting with JavaScript directly, you can use a special debug style property. When ExtendedCss meets this property, it enables the debugging mode either for a single selector or for all selectors, depending on the debug value.

Open the browser console while on a web page to see the timing statistics for selector(s) that were applied there. Debugging mode displays the following stats as object where each of the debugged selectors are keys, and value is an object with such properties:

Always printed:

  • selectorParsed — text of the parsed selector, may differ from the input one
  • timings — list of DOM nodes matched by the selector
    • appliesCount — total number of times that the selector has been applied on the page
    • appliesTimings — time that it took to apply the selector on the page, for each of the instances that it has been applied (in milliseconds)
    • meanTiming — mean time that it took to apply the selector on the page
    • standardDeviation — standard deviation
    • timingsSum — total time it took to apply the selector on the page across all instances

Printed only for remove pseudos:

  • removed — flag to signal if elements were removed

Printed if elements are not removed:

  • matchedElements — list of DOM nodes matched by the selector
  • styleApplied — parsed rule style declaration related to the selector

Příklady

Debugging a single selector:

When the value of the debug property is true, only information about this selector will be shown in the browser console.

#$?#.banner { display: none; debug: true; }

Enabling global debug:

When the value of the debug property is global, the console will display information about all extended CSS selectors that have matches on the current page, for all the rules from any of the enabled filters.

#$?#.banner { display: none; debug: global; }

Testing extended selectors without AdGuard

ExtendedCss can be executed on any page without using any AdGuard product. In order to do that you should copy and execute the following code in a browser console:

!function(e,t,d){C=e.createElement(t),C.src=d,C.onload=function(){alert("ExtendedCss loaded successfully")},s=e.getElementsByTagName(t)[0],s?s.parentNode.insertBefore(C,s):(h=e.getElementsByTagName("head")[0],h.appendChild(C))}(document,"script","https://AdguardTeam.github.io/ExtendedCss/extended-css.min.js");

Alternatively, install the ExtendedCssDebugger userscript.

Now you can now use the ExtendedCss from global scope, and run its method query() as Document.querySelectorAll().

Příklady

const selector = 'div.block:has=(.header:matches-css(after, content: Ads))';

// array of HTMLElements matched the `selector` is to be returned
ExtendedCss.query(selector);

Ladění skriptletů

If you are using AdGuard Browser Extension and want to debug a scriptlet or a trusted scriptlet rule, you can get additional information by opening the Filtering log. In that case, scriptlets will switch to debug mode and there will be more information in the browser console.

The following scriptlets are especially developed for debug purposes:

The following scriptlets also may be used for debug purposes:

Legenda tabulek kompatibility

Zkratky produktů

  1. aplikace CoreLibsAdGuard pro Windows, AdGuard pro Mac, AdGuard pro Android a AdGuard pro Linux
  2. AdGuard pro ChromiumRozšíření prohlížeče AdGuard pro Chrome a další prohlížeče založené na Chromium, např. nový Microsoft Edge a Opera
  3. Adguard pro Chrome MV3Rozšíření prohlížeče AdGuard pro Chrome MV3
  4. Adguard pro FirefoxRozšíření prohlížeče AdGuard pro Firefox
  5. AdGuard pro iOSAdGuard pro iOS a AdGuard pro iOS Pro (pro mobilní prohlížeč Safari)
  6. AdGuard pro SafariAdGuard pro desktopový prohlížeč Safari
  7. Blokátor obsahu AdGuardblokátor obsahu pro mobilní prohlížeče Android: Samsung Internet a Yandex Browser

Zkratky kompatibility

poznámka
  • ✅ — plně podporováno
  • ✅ * — podporováno, ale spolehlivost se může lišit nebo se mohou vyskytnout omezení; více informací naleznete v popisu modifikátoru
  • 🧩 — may already be implemented in nightly or beta versions but is not yet supported in release versions
  • ⏳ — feature that is planned to be implemented but is not yet available in any product
  • ❌ — nepodporováno
  • 👎 — zastaralé; stále podporovano, ale v budoucnu bude odstraněno
  • 🚫 — odstraněno a již nepodporováno