The declarativeNetRequest API is the modern, privacy-preserving way for extensions to block or modify network requests in Manifest V3.
What it does
- Allows extensions to specify rules that tell the browser how to handle network requests.
- The browser handles the request matching and actions, not the extension's JavaScript, which is faster and more private.
- Rules can block requests, redirect requests, or modify request/response headers.
- Rules are defined in JSON files within the extension or can be added/removed dynamically.
When to use it
This is the primary API for content blocking extensions in Manifest V3.
Examples:
- Ad blockers.
- Privacy extensions that block tracking scripts.
- Extensions that redirect requests to a more secure (HTTPS) version of a site.
- Parent control extensions that block access to certain websites.
Manifest Declaration
Using this API requires the declarativeNetRequest permission. Host permissions are only needed for rules whose action is redirect or modifyHeaders; pure block, allow, allowAllRequests, and upgradeScheme rules apply across origins without any host permissions.
{
"name": "My Content Blocker",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"declarativeNetRequest"
],
"host_permissions": [
"<all_urls>"
],
"declarative_net_request" : {
"rule_resources" : [{
"id": "ruleset_1",
"enabled": true,
"path": "rules.json"
}]
}
}Security & Privacy
Why is it not risky?
This is the modern, safe way for extensions like ad blockers to work. The extension gives the browser a list of rules (e.g., "block all requests from tracking.com") and the browser enforces them.
The key is that the extension cannot see your network activity. It just provides the rules and has no idea when they are used. This design protects your privacy while still allowing for effective content blocking. The installation warning you see is because the extension can still affect how websites load.
API Usage Example
Here is an example rules.json file that blocks all requests to ads.example.com.
// rules.json
[
{
"id": 1,
"priority": 1,
"action": { "type": "block" },
"condition": {
"urlFilter": "||ads.example.com^",
"resourceTypes": ["main_frame", "sub_frame", "script", "image"]
}
}
]Extensions with the declarativeNetRequest permission
Here are some popular browser extensions that use the "declarativeNetRequest" permission. To explore more, try our Advanced search.