#syntax #filter #rules #filtering #origin #parser #resources

adblock

Native Rust module for Adblock Plus syntax (e.g. EasyList, EasyPrivacy) filter parsing and matching.

121 releases

new 0.9.4 Dec 10, 2024
0.9.3 Nov 28, 2024
0.9.2 Oct 13, 2024
0.8.11 Jun 5, 2024
0.1.28 Jul 22, 2019

#249 in Parser implementations

Download history 310/week @ 2024-08-20 431/week @ 2024-08-27 209/week @ 2024-09-03 291/week @ 2024-09-10 1148/week @ 2024-09-17 744/week @ 2024-09-24 1036/week @ 2024-10-01 641/week @ 2024-10-08 474/week @ 2024-10-15 821/week @ 2024-10-22 434/week @ 2024-10-29 540/week @ 2024-11-05 294/week @ 2024-11-12 492/week @ 2024-11-19 1820/week @ 2024-11-26 4249/week @ 2024-12-03

6,880 downloads per month
Used in 4 crates (3 directly)

MPL-2.0 license

720KB
14K SLoC

adblock-rust

crates.io npmjs.com docs.rs Build Status License

Putting you back in control of your browsing experience.

adblock-rust is the engine powering Brave's native adblocker, available as a library for anyone to use. It features:

  • Network blocking
  • Cosmetic filtering
  • Resource replacements
  • Hosts syntax
  • uBlock Origin syntax extensions
  • iOS content-blocking syntax conversion
  • Compiling to native code or WASM
  • Rust bindings (crates)
  • JS bindings (npm)
  • Community-maintained Python bindings (pypi)
  • High performance!

Getting started

adblock-rust is used in several projects, including browsers, research tools, and proxies. It may be a good fit for yours, too!

See docs.rs for detailed API documentation.

Also check the Rust example or the NodeJS example.

Optional features

The following cargo features can be used to tweak adblock-rust to best fit your use-case.

CSS validation during rule parsing (css-validation)

When parsing cosmetic filter rules, it's possible to include a built-in implementation of CSS validation (through the selectors and cssparser crates) by enabling the css-validation feature. This will cause adblock-rust to reject cosmetic filter rules with invalid CSS syntax.

Content blocking format translation (content-blocking)

Enabling the content-blocking feature gives adblock-rust support for conversion of standard ABP-style rules into Apple's content-blocking format, which can be exported for use on iOS and macOS platforms.

External domain resolution (embedded-domain-resolver)

By default, adblock-rust ships with a built-in domain resolution implementation (through the addr crate) that will generally suffice for standalone use-cases. For more advanced use-cases, disabling the embedded-domain-resolver feature will allow adblock-rust to use an external domain resolution implementation instead. This is extremely useful to reduce binary bloat and improve consistency when embedding adblock-rust within a browser.

Parsing resources from uBlock Origin's formats (resource-assembler)

adblock-rust uses uBlock Origin-compatible resources for scriptlet injection and redirect rules. The resource-assembler feature allows adblock-rust to parse these resources directly from the file formats used by the uBlock Origin repository.

Thread safety (object-pooling, unsync-regex-caching)

The object-pooling and unsync-regex-caching features enable optimizations for rule matching speed and the amount of memory used by the engine. These features can be disabled to make the engine Send + Sync, although it is recommended to only access the engine on a single thread to maintain optimal performance.

Dependencies

~6–9MB
~170K SLoC