MCPcopy Index your code
hub / github.com/brave/adblock-rust

github.com/brave/adblock-rust @v0.12.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.12.4 ↗ · + Follow
1,397 symbols 3,375 edges 125 files 203 documented · 15%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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 (single-thread)

The single-thread feature enables optimizations for rule matching speed and the amount of memory used by the engine. This feature 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.

Extension points exported contracts — how you extend this code

FlatSerialize (Interface)
The trait to serialize structure into flatbuffer. Implement the traits directly if the structure has a direct representa [15 …
src/flatbuffers/containers/flat_serialize.rs
ResourceStorageBackend (Interface)
Customizable backend for [Resource] storage. Custom implementations could be used to enable (for example) sharing of res [2 …
src/resources/resource_storage.rs
NetworkFilterMaskHelper (Interface)
(no doc) [4 implementers]
src/filters/network.rs
RangeArg (Interface)
(no doc) [3 implementers]
src/url_parser/parser.rs
Optimization (Interface)
(no doc) [1 implementers]
src/optimizer.rs
MatchByStr (Interface)
(no doc) [1 implementers]
tests/unit/filters/cosmetic.rs
FbIndex (Interface)
A trait to access indexed data in a flatbuffer. It has two implementations: 1. a faster &[I] for slices; 2. a slower for [3 …
src/flatbuffers/containers/fb_index.rs
NetworkMatchable (Interface)
(no doc) [1 implementers]
src/filters/network.rs

Core symbols most depended-on inside this repo

iter
called by 168
src/filters/network.rs
check
called by 101
src/blocker.rs
contains
called by 97
src/flatbuffers/containers/hash_set.rs
slice
called by 90
src/url_parser/parser.rs
insert
called by 83
src/flatbuffers/containers/hash_map.rs
into_iter
called by 82
src/content_blocking.rs
filter_match_url
called by 81
tests/unit/filters/network_matchers.rs
len
called by 73
src/flatbuffers/containers/hash_map.rs

Shape

Function 598
Method 561
Class 177
Enum 47
Interface 14

Languages

Rust82%
TypeScript18%

Modules by API surface

data/test/fake-uBO-files/web_accessible_resources/google-ima.js166 symbols
src/flatbuffers/fb_network_filter_generated.rs110 symbols
src/filters/cosmetic.rs55 symbols
tests/unit/filters/cosmetic.rs46 symbols
tests/unit/flatbuffers/containers/test_containers_generated.rs45 symbols
src/filters/network.rs45 symbols
tests/unit/blocker.rs38 symbols
tests/legacy_harness.rs36 symbols
src/blocker.rs32 symbols
src/resources/resource_storage.rs31 symbols
src/engine.rs31 symbols
tests/unit/filters/network.rs30 symbols

For agents

$ claude mcp add adblock-rust \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact