Skip to content

Repository files navigation

PyBlock — Advanced Chrome Ad & Tracker Blocker

Manifest V3Python 3.12+License: MIT

PyBlock is a production-grade Manifest V3 Chrome Extension and Python rule compilation engine built for real-time network request blocking, tracker classification, domain analytics, and cosmetic element cleanup.

PyBlock is designed with a dual architecture philosophy:

  1. Standalone Chrome Extension: Operates 100% inside Google Chrome using native declarativeNetRequest (DNR) APIs with zero reliance on local databases, proxy servers, or background Python processes during browsing.
  2. Optional Python Processing Engine: An offline/local microservice for fetching, parsing, optimizing, deduplicating, validating, and compiling standard filter lists (ABP, uBlock Origin, Hosts files) into Chrome MV3 compliant JSON rulesets.

Key Features

  • 🛡️ Declarative Network Request (DNR) Blocking: Intercepts ad servers, telemetry endpoints, tracking pixels, and malicious redirects at the browser network layer with minimal memory and CPU overhead.
  • 🎯 Domain & Tracker Classification: Categorizes request patterns into Advertising, Analytics, Fingerprinting, Social Tracking, Telemetry, and Annoyances.
  • 🧹 Cosmetic Cleanup & Anti-Adblock Mitigation: Hides blank ad slots and suppresses soft anti-adblock overlay backdrops without breaking page layout or script execution.
  • Dynamic Rule Whitelisting: Per-site instant protection pause/resume that dynamically updates MV3 allow rules in real time.
  • 📊 Cybersecurity Dashboard & Popup UI: Modern dark theme glassmorphism interfaces displaying block statistics, category breakdowns, recent request logs, and whitelist managers.
  • 🔧 Python Optimization Pipeline: Rule parser, deduplicator, ID conflict resolver, schema validator, and rule generator adhering to Chrome MV3 quotas.

Directory Architecture

PyBlock/
├── extension/
│ ├── manifest.json # Manifest V3 setup with DNR, storage, scriptings permissions
│ ├── background/
│ │ └── service-worker.js # DNR rule state, badge counters, popup messaging, whitelist sync
│ ├── content/
│ │ ├── content.js # Cosmetic filtering (hiding empty ad containers), anti-adblock mitigation
│ │ └── content.css # Base cosmetic hide rules
│ ├── popup/
│ │ ├── popup.html # Compact extension popup UI (Stats, Toggle, Refresh, Quick Links)
│ │ ├── popup.css # Dark/Light cybersecurity theme styling
│ │ └── popup.js # Popup logic, communication with service-worker
│ ├── dashboard/
│ │ ├── dashboard.html # Full-page analytics & statistics dashboard
│ │ ├── dashboard.css # Glassmorphism/Dark modern UI theme
│ │ └── dashboard.js # Statistics display, request logs, domain breakdowns
│ ├── settings/
│ │ ├── settings.html # Settings manager (Protection modes, Whitelist, Custom Rules, Python API link)
│ │ ├── settings.css # Settings visual styles
│ │ └── settings.js # Settings persistence using chrome.storage.local
│ ├── rules/
│ │ └── generated-rules.json # Pre-compiled MV3 declarativeNetRequest rule file
│ └── icons/ # 16px, 48px, 128px PyBlock branding icons
│
├── python/
│ ├── main.py # CLI & optional FastAPI/Flask local service runner
│ ├── rule_parser.py # ABP / uBlock filter list line parser (domains, options, types)
│ ├── rule_generator.py # Rule compiler (maps parsed rules to MV3 DNR JSON format)
│ ├── domain_classifier.py # Category classifier (Ads, Analytics, Social, Cryptomining, Telemetry)
│ ├── tracker_classifier.py # Advanced domain fingerprinting & tracker category analyzer
│ ├── validator.py # DNR schema validator, ID collision check, Chrome limits verification
│ └── updater.py # HTTP filter list retriever with fallback caching
│
├── rules/ # Raw & intermediate configuration files
│ ├── ads.json # Raw ad domains & URL patterns
│ ├── trackers.json # Raw tracking endpoints
│ ├── privacy.json # Privacy & telemetry patterns
│ ├── annoyances.json # Popup overlays & cosmetic block targets
│ ├── custom.json # User-defined custom rules
│ └── whitelist.json # Domain/URL whitelisting rules
│
├── config/
│ └── settings.json # Default extension configuration & filter source URLs
│
├── tests/
│ ├── test_parser.py # Pytest suite for filter list syntax parsing
│ ├── test_matcher.py # Python matcher verification tests
│ └── test_rules.py # Rule validation, schema conformity, deduplication tests
│
├── requirements.txt # Python dependencies (requests, pydantic, fastapi, pytest, etc.)
├── README.md # Comprehensive technical documentation
└── LICENSE # MIT License

Installation & Setup

1. Load Standalone Extension in Google Chrome

  1. Open Google Chrome and navigate to chrome://extensions.
  2. Enable Developer mode in the top right corner.
  3. Click Load unpacked.
  4. Select the PyBlock/extension directory.
  5. Click the PyBlock shield icon in your Chrome toolbar!

2. Python Rule Engine Setup (Optional / Developer)

To fetch external lists, parse customized rules, or run the local FastAPI microservice:

  1. Install dependencies:

    pip install -r requirements.txt
  2. Compile and optimize raw rules into extension rules:

    python python/main.py --build
  3. Validate compiled rule schema:

    python python/main.py --validate
  4. Run automated unit test suite:

    pytest tests/
  5. (Optional) Run local API microservice:

    python python/main.py --serve

    Microservice exposes GET /status, POST /rules/update, POST /rules/validate, GET /classify?domain=... on http://127.0.0.1:8765.


Security & Architecture Principles

  • No Remote Code Execution: Full compliance with Manifest V3 policies. No eval(), no remote script injection, no untrusted HTML string innerHTML manipulation.
  • Privacy-First: No database required. Lightweight local storage (chrome.storage.local) holds user preferences and session statistics.
  • Fail-Safe Operation: If external filter sources or the local Python server are unreachable, PyBlock continues executing with its built-in generated ruleset.

Limitations

  • Ad-Block Detection: No ad blocker can guarantee 100% bypass of complex server-side anti-adblock paywalls. PyBlock uses safe, non-intrusive cosmetic hiding.
  • Manifest V3 Ruleset Limits: Chrome restricts static rules to 30,000 rules per ruleset. PyBlock's Python engine automatically prunes and deduplicates rules to adhere to Chrome limits.

License

Distributed under the MIT License.

About

A privacy-focused Chrome extension that blocks ads, trackers, unwanted network requests, and redirects using Manifest V3, with a Python-powered rule processing engine and real-time security analytics.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages