declarativeNetRequest API. You declare matching rules, and the browser blocks requests natively before they leave the network stack.
What you build
Why MV3 replaced blocking webRequest
Manifest V2 ad blockers registered blockingwebRequest listeners. Every request paused while extension JavaScript decided its fate. Manifest V3 removed that model for performance and privacy reasons. With declarativeNetRequest, the browser evaluates your rules itself. Your code never sits on the request path and never reads request contents to block them.
For proxy-style use cases, such as routing all traffic through another server, use the proxy API instead of request rules.
Manifest
Block and allow rules need no host permissions. Redirect rules and header rules need host permissions for the affected sites.manifest.json
rule_resources references and emits it with the build output.
Static rules
Static rules live inrules.json and load when the extension loads.
rules.json
||domain^ filter syntax matches a domain and all of its subdomains.
Dynamic rules
Use dynamic rules for filters that change at runtime, such as user-added blocklist entries. Remove a rule id before you re-add it, so updates stay idempotent.background.js
declarativeNetRequest reference before you ship large filter lists.
Count blocked requests on the badge
One call turns the action badge into a per-tab counter of matched rules.background.js
getMatchedRules, add the declarativeNetRequestFeedback permission.
Run it
Before you editmanifest.json, know that manifest changes need a dev-server restart. See Dev update behavior.
Firefox notes
- Firefox supports
declarativeNetRequestin Manifest V3. - Firefox does not support
setExtensionActionOptions, so the badge counter is Chromium-only. - Firefox still allows blocking
webRequestin Manifest V3, which Chrome reserves for policy installs. - Use browser-specific manifest fields when the two targets diverge.
Start from a template
Theaction template ships a background script plus a toolbar popup, a good base for a blocker UI.
Best practices
- Keep static rules in
rules.jsonand reserve dynamic rules for user choices. - Give every dynamic rule a stable id, so removals stay predictable.
- Scope
resourceTypesto what you block, not to every type. - Prefer block and allow rules, which need no host permissions.
- Test rules against real pages before you publish filter updates.
Next steps
- Observe traffic without blocking it in Intercept network requests.
- Audit your permission surface with the Security checklist.
- Review Manifest V3 concepts for the background model.

