Declarative Net Request Rules, Rulesets, Limits and Match APIs
How Chrome extension declarativeNetRequest manages static, dynamic, and session rules, rulesets, quotas, and match debugging.
This page summarises Chrome extension API reference documentation for the declarativeNetRequest API (Manifest V3). The same methods are documented for the chrome.* namespace on the Manifest V2 declarativeNetRequest reference; on MV3 and later they return Promises, while older platforms may still use optional callbacks.
The API lets an extension block, redirect, or modify network requests using declarative rules that the browser evaluates efficiently, instead of intercepting each request in JavaScript. You manage static rules (shipped in the package), dynamic rules (updated at runtime and persisted), and session rules (in memory for the current browser session), grouped into rulesets.
declarativeNetRequest rule types: static, dynamic, and session
Section titled “declarativeNetRequest rule types: static, dynamic, and session”A Rule combines an action (what to do when matched), a condition (when it applies), a mandatory numeric id (unique, >= 1), and optional priority (defaults to 1, and when set should be >= 1).
Static rules live in JSON files referenced from the manifest. Each static Ruleset has a non-empty string id (IDs starting with _ are reserved), a path relative to the extension directory, and enabled indicating whether the ruleset is on by default. You enable or disable whole rulesets at runtime; individual static rules can be toggled inside an enabled ruleset.
Dynamic rules are added or removed with updateDynamicRules. Session rules use the same update shape via updateSessionRules, but they are not persisted.
Modifies the current set of dynamic rules for the extension. The rules with IDs listed in options.removeRuleIds are first removed, and then the rules given in options.addRules are added.
— Chrome, browser.declarativeNetRequest
Modifies the current set of session scoped rules for the extension.
— Chrome, browser.declarativeNetRequest
| Rule storage | Update method | Persisted across browser restart? | Persisted across extension update? |
|---|---|---|---|
| Static (packaged JSON) | updateEnabledRulesets, updateStaticRules |
Enabled set: yes for sessions; static file content: yes | Enabled rulesets reset to manifest rule_resources defaults |
| Dynamic | updateDynamicRules |
Yes | Yes |
| Session | updateSessionRules |
No (in memory) | No |
updateDynamicRules and updateSessionRules: atomic add/remove
Section titled “updateDynamicRules and updateSessionRules: atomic add/remove”Both methods accept UpdateRuleOptions with optional addRules (Rule[]) and removeRuleIds (number[]). Invalid IDs in removeRuleIds are ignored for removals.
This update happens as a single atomic operation: either all specified rules are added and removed, or an error is returned.
— Chrome, browser.declarativeNetRequest
For dynamic rules, persistence is explicit:
These rules are persisted across browser sessions and across extension updates.
— Chrome, browser.declarativeNetRequest
Session rules use the same atomic semantics but:
These rules are not persisted across sessions and are backed in memory.
— Chrome, browser.declarativeNetRequest
On failure, the promise rejects and no change is applied—common causes include invalid rule format, duplicate rule ID, rule count limits, and internal errors (documented on the returns sections of browser.declarativeNetRequest and chrome.declarativeNetRequest).
updateEnabledRulesets: which static rulesets are active
Section titled “updateEnabledRulesets: which static rulesets are active”updateEnabledRulesets disables rulesets listed in disableRulesetIds, then enables those in enableRulesetIds.
Note that the set of enabled static rulesets is persisted across sessions but not across extension updates, i.e. the rule_resources manifest key will determine the set of enabled static rulesets on each extension update.
— Chrome, browser.declarativeNetRequest
updateStaticRules: enable or disable individual static rules
Section titled “updateStaticRules: enable or disable individual static rules”updateStaticRules takes rulesetId plus optional disableRuleIds and enableRuleIds for rules inside that ruleset.
Changes to rules belonging to a disabled Ruleset will take effect the next time that it becomes enabled.
— Chrome, browser.declarativeNetRequest
Reading rules and rulesets: getDynamicRules, getSessionRules, getEnabledRulesets
Section titled “Reading rules and rulesets: getDynamicRules, getSessionRules, getEnabledRulesets”Use these read APIs to inspect current state (optionally filtered):
getDynamicRules(filter?)— current dynamicRule[]; may reject on transient internal errors.getSessionRules(filter?)— current session-scoped rules.getEnabledRulesets()— string IDs of enabled static rulesets.getDisabledRuleIds(options)— numeric IDs of disabled static rules in a given ruleset (Chrome 111+).getAvailableStaticRuleCount()— how many more static rules can be enabled before the global static rule cap.
GetRulesFilter can narrow fetches with optional ruleIds (“only rules with matching IDs are included” in the type definitions on browser.declarativeNetRequest).
Rule limits: MAX_NUMBER_OF_DYNAMIC_RULES and static quotas
Section titled “Rule limits: MAX_NUMBER_OF_DYNAMIC_RULES and static quotas”The reference ties updates to hard caps:
MAX_NUMBER_OF_DYNAMIC_RULESis the maximum number of dynamic rules an extension can add. The number of unsafe rules must not exceedMAX_NUMBER_OF_UNSAFE_DYNAMIC_RULES.
— Chrome, browser.declarativeNetRequest
MAX_NUMBER_OF_SESSION_RULESis the maximum number of session rules an extension can add.
— Chrome, browser.declarativeNetRequest
Before enabling large static rulesets, call getAvailableStaticRuleCount() to see remaining capacity under the global static rule limit.
Enabling many static rulesets can also fail with “rule count limit exceeded” on updateEnabledRulesets, as noted in that method’s return documentation on browser.declarativeNetRequest.
regexFilter rules: isRegexSupported before you ship
Section titled “regexFilter rules: isRegexSupported before you ship”Rule conditions may use regex filters. Call isRegexSupported(regexOptions) before relying on a pattern; the result includes isSupported and, when false, optional reason (UnsupportedRegexReason).
Checks if the given regular expression will be supported as a regexFilter rule condition.
— Chrome, browser.declarativeNetRequest
getMatchedRules and testMatchOutcome: debugging which rule matched
Section titled “getMatchedRules and testMatchOutcome: debugging which rule matched”getMatchedRules: live match history (permissions and TTL)
Section titled “getMatchedRules: live match history (permissions and TTL)”getMatchedRules(filter?) returns RulesMatchedDetails with rulesMatchedInfo entries describing matches. Optional MatchedRulesFilter fields include minTimeStamp, and tabId (use -1 for rules not tied to an active tab).
This method is only available to extensions with the “declarativeNetRequestFeedback” permission or having the “activeTab” permission granted for the tabId specified in filter. Note: Rules not associated with an active document that were matched more than five minutes ago will not be returned.
— Chrome, browser.declarativeNetRequest
Rejections can reflect insufficient permissions or exceeding quota (documented on the same page).
Each MatchedRuleInfo can include ruleId, rulesetId (dynamic rules use DYNAMIC_RULESET_ID), plus request and rule details.
testMatchOutcome: hypothetical requests during development
Section titled “testMatchOutcome: hypothetical requests during development”testMatchOutcome(request) answers whether existing rules would match a fabricated request and returns matchedRules.
Note: Only available for unpacked extensions as this is only intended to be used during extension development.
— Chrome, browser.declarativeNetRequest
setExtensionActionOptions: badge counts for blocked requests
Section titled “setExtensionActionOptions: badge counts for blocked requests”setExtensionActionOptions(options) configures whether per-tab action counts appear on the extension action badge and how counts increment—useful when rules use actions that participate in feedback counting (see browser.declarativeNetRequest).
browser.* vs chrome.* namespaces
Section titled “browser.* vs chrome.* namespaces”Chrome documents parallel browser.declarativeNetRequest and chrome.declarativeNetRequest APIs with the same shapes. The MV2 reference notes that Promises are only supported for Manifest V3 and later; on other platforms, optional callbacks remain the compatibility path (chrome.declarativeNetRequest).
Common mistakes
Section titled “Common mistakes”- Assuming
updateDynamicRulescan delete packaged static rules—it cannot. - Expecting enabled static rulesets to survive an extension update—they revert per manifest
rule_resources. - Calling
getMatchedRuleswithoutdeclarativeNetRequestFeedbackor appropriateactiveTabaccess. - Shipping regex conditions without calling
isRegexSupportedfirst. - Relying on
testMatchOutcomein a packed extension—it is development-only for unpacked loads.
How to check this on your site
Section titled “How to check this on your site”-
Load your unpacked extension and open
chrome://extensions, confirm Manifest V3 and thatdeclarativeNetRequestpermission and any neededrule_resourcesentries match browser.declarativeNetRequest. -
In the service worker console, run
await chrome.declarativeNetRequest.getEnabledRulesets()andawait chrome.declarativeNetRequest.getDynamicRules()to verify rulesets and dynamic rules match what you expect. -
If you use regex conditions, run
chrome.declarativeNetRequest.isRegexSupported({ regex: '…' })for each pattern before enabling rules. -
Trigger network requests on a test page, then call
getMatchedRules({ tabId })only if you declareddeclarativeNetRequestFeedbackor haveactiveTabfor that tab; compare results withtestMatchOutcomefor the same URL while developing unpacked. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.