Crate adblock

source
Expand description

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!

Check the Engine documentation to get started with adblocking.

Modules§

  • Holds Blocker, which handles all network-based adblocking queries.
  • Provides behavior related to cosmetic filtering - that is, modifying a page’s contents after it’s been loaded into a browser. This is primarily used to hide or clean up unwanted page elements that are served inline with the rest of the first-party content from a page, but can also be used to inject JavaScript “scriptlets” that intercept and modify the behavior of scripts on the page at runtime.
  • Contains representations and standalone behaviors of individual filter rules.
  • Parsing functions and collections for handling with multiple filter rules.
  • Compiled regexes can take up large amounts of memory. To reduce the overall memory footprint of the crate::Engine, infrequently used regexes can be discarded. The RegexManager is responsible for managing the storage of regexes used by filters.
  • Contains structures needed to describe network requests.
  • In adblocking terms, Resources are special placeholder scripts, images, video files, etc. that can be returned as drop-in replacements for harmful equivalents from remote servers. Resources also encompass scriptlets, which can be injected into pages to inhibit malicious behavior.
  • Simplified URL parsing infrastructure, including the domain resolver implementation if the embedded-domain-resolver feature is disabled.

Structs§

  • Drives high-level blocking logic and is responsible for loading filter lists into an optimized format that can be queried efficiently.
  • Manages a set of rules to be added to an crate::Engine.