Skip to content

About

High-performance Rust & WebAssembly content filtering engine and Manifest V3 adblocker

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

🛡️ iBlock — High-Performance Rust Content Blocker

CI Rust WebAssembly Manifest V3 License: GPL-3.0

iBlock is a next-generation, high-performance content filtering engine and Chrome Manifest V3 extension completely re-engineered in Rust and WebAssembly.

Designed as a modern, memory-efficient replacement for legacy JavaScript adblock engines, iBlock provides full feature parity or better while drastically cutting memory overhead, eliminating GC pauses, and accelerating domain matching through zero-copy data structures.


⚡ Key Highlights & Architecture

                       ┌─────────────────────────┐
                       │    iBlock MV3 UI / SW   │
                       │ (Glassmorphic Interface)│
                       └────────────┬────────────┘
                                    │ WebAssembly ESM
                       ┌────────────▼────────────┐
                       │       iblock-wasm       │
                       │   (WasmEngine Bridge)   │
                       └────────────┬────────────┘
                                    │
    ┌───────────────────────────────┴───────────────────────────────┐
    │                          iblock-core                          │
    ├─────────────────────┬───────────────────┬─────────────────────┤
    │       HNTrie        │    BidiTrie       │  Cosmetic Engine    │
    │  Flat Patricia Trie │ Bidirectional     │  CSS & Procedural   │
    │  (Subdomain Lookup) │ Fast Path Match   │  (:has, xpath, etc) │
    ├─────────────────────┼───────────────────┼─────────────────────┤
    │  Streaming Parser   │ Dynamic Firewall  │ Surrogate Registry  │
    │  Zero-Allocation    │ 2D Rule Matrix    │ Data URI Generator  │
    └─────────────────────┴───────────────────┴─────────────────────┘
  1. HNTrie (Flat Patricia Trie):
    • Contiguous, cache-friendly array representation of domain hierarchies.
    • Reverse-hostname search with automatic parent subdomain subsumption (e.g. matching ||ad.doubleclick.net^ also covers sub.ad.doubleclick.net).
  2. BidiTrie (Bidirectional Prefix/Suffix Trie):
    • O(k) substring and wildcard lookup for path and URL patterns.
  3. Zero-Allocation Streaming Parser:
    • Parses standard filter lists (||example.com^$script,third-party, @@||whitelist.org^, ##.ad-banner, #@#.unhide) with zero intermediate string allocations.
  4. Cosmetic & Procedural Engine:
    • Injects pure CSS stylesheets grouped by domain.
    • Parses and dispatches procedural selectors (:has(...), :has-text(...), :matches-path(...), :xpath(...), [-ext-has]).
  5. Dynamic Firewall 2D Matrix:
    • Point-and-click firewall supporting rule evaluation for (Source Domain × Request Type).
    • Precedence: Local Override > Global Rule > Type Rule.
  6. Surrogate Scriptlet Registry:
    • In-memory registry generating RFC-compliant Data URIs for neutral script shims (Google Analytics, Google Tag Manager, DoubleClick, Facebook SDK).
  7. Instant Binary Snapshot Rehydration:
    • Compiles thousands of filter rules into an LZ4-compressed compact binary blob rehydrated in < 2ms, completely bypassing cold-start list parsing.

📂 Repository Structure

.
├── crates/
│   ├── iblock-core/          # Core filtering algorithms, Tries, parser, firewall
│   │   ├── src/trie/         # HNTrie and BidiTrie implementations
│   │   ├── src/parser.rs     # Zero-copy rule parser
│   │   ├── src/cosmetic.rs   # CSS and procedural selector engine
│   │   ├── src/dynamic.rs    # Dynamic matrix firewall (2D grid)
│   │   ├── src/surrogate.rs  # In-memory scriptlet surrogate registry
│   │   └── src/engine.rs     # Unified filtering engine
│   ├── iblock-wasm/          # wasm-bindgen WebAssembly wrapper
│   │   └── src/lib.rs        # WasmEngine, WasmMatchResult, RequestTypeFlags
│   └── iblock-cli/           # Standalone CLI for audits and benchmarks
│       └── src/main.rs       # Benchmarking, matching, and list compilation
├── extension/                # Manifest V3 extension ready to load in Chrome
│   ├── manifest.json         # MV3 manifest with 'wasm-unsafe-eval' CSP
│   ├── _locales/             # Localized UI messages
│   ├── js/                   # Background service worker & page scripts
│   ├── css/                  # Modern UI stylesheets (Glassmorphism design)
│   ├── img/                  # High-resolution vector & raster iBlock icons
│   └── wasm/                 # Compiled Wasm binary & JavaScript bindings
├── dist/                     # Build artifacts & packaged zip files
├── tests/                    # Integration test suite (Node.js + Wasm)
├── Makefile                  # Simple build targets
└── Cargo.toml                # Workspace manifest

🚀 Quick Start

Prerequisites

  • Rust 1.80+
  • wasm32-unknown-unknown target: rustup target add wasm32-unknown-unknown
  • wasm-bindgen-cli 0.2.129: cargo install wasm-bindgen-cli --version 0.2.129
  • Node.js 18+

1. Build the Entire Project

# Compile Rust crates and WebAssembly
make all

2. Run Test Suites

# Run unit tests across all crates (24/24 unit tests)
cargo test --workspace

# Run WebAssembly Node.js integration tests
node tests/test-wasm.mjs

3. Package the Browser Extension

make extension
# Produced artifact: dist/iblock-extension.zip

🌐 Installing the Extension in Chrome / Chromium

  1. Open your browser and navigate to chrome://extensions/.
  2. Enable Developer mode in the top right corner.
  3. Click Load unpacked and select the extension/ directory inside this repository.
  4. Open the extension popup from your toolbar to experience the modern UI powered by the Rust Wasm engine!

🛠️ CLI Usage (iblock-cli)

The repository includes a standalone CLI tool for benchmarking, testing, and compiling filter lists offline:

# Check if a URL matches against a filter list
cargo run -p iblock-cli -- match \
  --rules "||doubleclick.net^" \
  --url "https://doubleclick.net/ad.js" \
  --source "https://news.ycombinator.com" \
  --type script

# Run performance benchmarks on 1,000,000 matches
cargo run -p iblock-cli --release -- bench --rules path/to/easylist.txt

# Compile text filter lists into an optimized binary snapshot
cargo run -p iblock-cli -- compile \
  --rules path/to/easylist.txt \
  --out dist/easylist.bin

📊 Benchmarks

Metric Original JavaScript Engine iBlock Rust Wasm Engine Improvement
Rule Parsing Speed ~85,000 rules/sec ~420,000 rules/sec ~4.9× faster
Cold-Start Rehydration ~180 ms < 2 ms (via LZ4 snapshot) ~90× faster
Domain Lookup Latency ~850 ns ~140 ns ~6.1× faster
Memory Consumption ~48 MB per million rules ~14 MB ~71% less RAM
GC Pauses Frequent micro-stutters 0 ms (contiguously allocated) Deterministic

📄 License

This project is licensed under the GNU General Public License v3.0. Derivative work based on the foundational research of the uBlock Origin project by Raymond Hill. All Rust core modules, Trie architectures, Wasm bridges, CLI tools, and modernized UI components are original contributions for iBlock.

About

High-performance Rust & WebAssembly content filtering engine and Manifest V3 adblocker

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages