Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Declarative Net Request Rules, Rulesets, Evaluation and Migration

How browser extensions block and modify network traffic with declarativeNetRequest rules, limits, prioritization, and Manifest V3 migration from webRequest.

This page summarizes Chrome extension documentation on declarative net request: declaring rules that block, redirect, upgrade, or modify headers without running JavaScript on every request. In Manifest V3, that model replaces blocking webRequest listeners for most extensions; policy-installed extensions can still use programmatic blocking.

The chrome.declarativeNetRequest API is used to block or modify network requests by specifying declarative rules. This lets extensions modify network requests without intercepting them and viewing their content, thus providing more privacy.

— Chrome, browser.declarativeNetRequest

declarativeNetRequest vs webRequest: when to use which API

Section titled “declarativeNetRequest vs webRequest: when to use which API”

declarativeNetRequest is the primary way to filter network requests in Manifest V3 extensions. Rules are evaluated in the browser, not in your service worker on each request.

webRequest still lets you observe and analyze traffic. Blocking and in-flight modification require webRequestBlocking, which Chrome documents as unavailable for most Manifest V3 extensions:

Note: As of Manifest V3, the “webRequestBlocking” permission is no longer available for most extensions. Consider “declarativeNetRequest”, which enables use the declarativeNetRequest API.

— Chrome, browser.webRequest

Goal Typical API Notes
Block, redirect, upgrade scheme, modify headers at scale declarativeNetRequest Declarative rules; no per-request extension callback
Observe requests, learn patterns, add dynamic rules later webRequest (non-blocking) + updateDynamicRules() See content filtering
Full programmatic filter on every request webRequest with blocking Policy-installed extensions only

The older declarativeWebRequest API is deprecated in favor of declarativeNetRequest.

Permissions and manifest: declarative_net_request rule_resources

Section titled “Permissions and manifest: declarative_net_request rule_resources”

Declare the API permission in manifest.json. Chrome offers two main permission strings with the same capabilities but different install-time behavior:

“declarativeNetRequest” — Triggers a permission warning at install time but provides implicit access to allow, allowAllRequests and block rules. Use this when possible to avoid needing to request full access to hosts.

“declarativeNetRequestWithHostAccess” — A permission warning is not shown at install time, but you must request host permissions before you can perform any action on a host.

— Chrome, browser.declarativeNetRequest

For static rulesets (JSON packaged with the extension), also set the declarative_net_request manifest key with rule_resources pointing at rule files—see browser.declarativeNetRequest — Manifest.

Optional declarativeNetRequestFeedback enables debugging for unpacked extensions (getMatchedRules(), onRuleMatchedDebug).

Redirects to specific hosts often need declarativeNetRequestWithHostAccess plus matching host_permissions, as described in the redirect migration example.

Rulesets: static, dynamic, and session rules

Section titled “Rulesets: static, dynamic, and session rules”

A ruleset is an array of rules. Each rule has an id, priority, action, and condition (see Build rules).

Type How it is managed Lifetime
Static JSON files + rule_resources in the manifest; enable/disable via updateEnabledRulesets() / updateStaticRules() Installed/updated with the extension; enabled set persists across sessions but not across extension updates
Dynamic updateDynamicRules() while the extension runs Persists across sessions and extension upgrades
Session updateSessionRules() Cleared on browser shutdown and on extension update

There is only one each of these ruleset types. An extension can add or remove rules to them dynamically by calling updateDynamicRules() and updateSessionRules(), provided the rule limits aren’t exceeded.

— Chrome, browser.declarativeNetRequest

Static rule files: load the extension unpacked to see errors; invalid static rules in packed builds are ignored (Static rulesets).

Bulk updates for dynamic rules follow the pattern in Update dynamic rules: fetch current IDs, then pass removeRuleIds and addRules together.

From the action enum:

  • block — stop the request
  • redirect — URL, extensionPath, transform, or regexSubstitution
  • upgradeScheme — http/ftp → https
  • allow / allowAllRequests — exceptions; allowAllRequests covers a frame hierarchy
  • modifyHeaders — change request or response headers

Example block rule (from Build rules):

{
"id" : 1,
"priority": 1,
"action" : { "type" : "block" },
"condition" : {
"urlFilter" : "abc",
"initiatorDomains" : ["foo.com"],
"resourceTypes" : ["script"]
}
}

Cookie removal via headers matches the Headers example (modifyHeaders + operation: "remove" on cookie).

Rule evaluation lifecycle: before request, headers, and response

Section titled “Rule evaluation lifecycle: before request, headers, and response”

DNR rules run at stages of the network request lifecycle (Rule evaluation).

Matching rules can block, redirect, or upgrade before the request is sent. Per extension, Chrome picks at most one candidate, ordering by priority, then by action type (allow / allowAllRequests > block > upgradeScheme > redirect in the documented ordering).

When multiple extensions conflict, Chrome chooses among block > redirect or upgradeScheme > allow, with the most recently installed extension winning ties of the same type (Before the request).

modifyHeaders rules apply before headers are sent or after response headers arrive, with constraints: append/set/remove interactions between rules depend on priority (Before request headers are sent).

Rules that match response headers can still run after the server has seen the request body. A late block or redirect cannot undo that; consider privacy implications (Once a response is received).

priority and urlFilter: which rule wins on a URL

Section titled “priority and urlFilter: which rule wins on a URL”

Use the numeric priority field plus action and how specific the urlFilter is. Chrome’s priority examples walk through google.com navigations: higher priority wins; at equal priority, allow beats block beats redirect.

For redirects into the extension package, declare targets in web_accessible_resources; otherwise redirects error (Web accessible resources)—the same constraint applies to webRequest redirects.

Rule limits and safe rules for content filtering

Section titled “Rule limits and safe rules for content filtering”

Content filtering describes how ad-block-style lists map to DNR.

Static rules (current reference values):

An extension can specify up to 100 static rulesets… but only 50 of these rulesets can be enabled at a time… Collectively, those rulesets are guaranteed at least 30,000 rules.

— Chrome, browser.declarativeNetRequest — Static rules

Chrome also documents a shared pool of 300,000 static rules across installed extensions, with per-extension guarantees described on the content filtering — Bundle filter rules page.

Dynamic rules: safe rules (block, allow, allowAllRequests, upgradeScheme) get a higher dynamic quota (30,000 from Chrome 121 per cluster); unsafe rules (e.g. some redirects) share a lower cap (5,000) that also counts toward the safe pool.

Session rules: up to 5,000 (MAX_NUMBER_OF_SESSION_RULES).

Use getAvailableStaticRuleCount() before enabling more static rules; getMatchedRules() is rate-limited except on user gesture (GETMATCHEDRULES quota).

Section titled “Service workers, cache, and declarativeContent (related APIs)”

Service workers: DNR applies to requests that reach the network stack, including HTTP cache hits, but not responses served only from a service worker’s synthetic onfetch / CacheStorage without fetch() to the network (Interactions with service workers).

Imperative webRequest caching: in-memory cache hits may be invisible to listeners; handlerBehaviorChanged() flushes cache but is expensive and rate-limited (webRequest — Caching).

Declarative content (not network): declarativeContent shows or hides the extension action from page signals (URL, CSS selectors) without the broad “read page content” permission model:

Use the chrome.declarativeContent API to take actions depending on the content of a page, without requiring permission to read the page’s content.

— Chrome, browser.declarativeContent

It uses the shared declarative events pattern (addRules, removeRules, bulk registration, persistent rules on runtime.onInstalled) from browser.events.

From Content filtering:

  1. Bundle large lists as static rules; update via dynamic rules or server-driven config.
  2. Observe with non-blocking webRequest, then updateDynamicRules() to block similar URLs later.
  3. User-defined filters in the UI → dynamic rules (persist across sessions).
  4. Navigation trackers — redirect main frames to an extension page (web-accessible) that extracts the real target, as described under Intercept navigation requests.

Manifest V2 blocking listeners: common migration mappings

Section titled “Manifest V2 blocking listeners: common migration mappings”

The Replace blocking web request listeners guide gives concrete before/after examples:

Manifest V2 pattern Manifest V3 approach
onBeforeRequest + { cancel: true } Static/dynamic rule with "action": { "type": "block" } and urlFilter
onBeforeRequest + redirectUrl "type": "redirect" with redirect.url
onBeforeSendHeaders remove cookie "type": "modifyHeaders" on requestHeaders

Blocking example.com often needs only declarativeNetRequest without host permissions in the manifest; redirects typically need host access permissions as shown in the same guide.

The Manifest V3 migration checklist lists “Replace blocking web request listeners” as a core migration step.

Chrome Web Store: eligible updates that change only safe static rules in existing rule_resources may skip review when other conditions are met.

  • Registering static rules with syntax errors in a packed build (rules silently ignored).
  • Assuming response-header block rules hide request bodies already sent to the origin.
  • Relying on tie order between rules with the same priority and action across runs or extensions.
  • Redirecting to extension files not listed in web_accessible_resources.
  • Calling addRules one rule at a time on declarative events (prefer bulk addRules / removeRules per events — Performance).
  • Using blocking webRequest in a normal MV3 extension instead of DNR or policy install.
  • Forgetting to removeRules then addRules on runtime.onInstalled when updating declarative content or legacy declarative web request rules (rules persist across sessions).
  1. Load the extension unpacked and fix any static rule errors reported for rule files (Static rulesets).

  2. Add declarativeNetRequestFeedback and use getMatchedRules() or onRuleMatchedDebug while reproducing the page load (Permissions).

  3. Open Chrome DevTools and use the Network panel to confirm blocked, redirected, or upgraded requests match your conditions.

  4. Call getAvailableStaticRuleCount() and compare enabled rulesets against documented caps before shipping large filter lists (Enable and disable static rules).

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about, and we will correct or clarify it.