Get to know MDN better
This API enables extensions to specify conditions and actions that describe how network requests should be handled. These declarative rules enable the browser to evaluate and modify network requests without notifying extensions about individual network requests.
To use this API, an extension must request the "declarativeNetRequest" or "declarativeNetRequestWithHostAccess" permission in its manifest.json file. The "declarativeNetRequest" permission is shown to users in permission prompts, the "declarativeNetRequestWithHostAccess" is not.
The "declarativeNetRequest" permission allows extensions to block and upgrade requests without any host permissions. Host permissions are required if the extension wants to redirect requests or modify headers on requests or when the "declarativeNetRequestWithHostAccess" permission is used instead of the "declarativeNetRequest" permission. To act on requests in these cases, host permissions are required for the request URL. For all requests, except for navigation requests (i.e., resource type main_frame and sub_frame), host permissions are also required for the request's initiator. The initiator of a request is usually the document or worker that triggered the request.
Some requests are restricted and cannot be matched by extensions. These include privileged browser requests, requests to or from restricted domains, and requests from other extensions.
The "declarativeNetRequestFeedback" permission is required to use getMatchedRules and onRuleMatchedDebug as they return information on declarative rules matched. See Testing for more information.
The declarative rules are defined by four fields:
Note: A redirect action does not redirect the request, and the request continues as usual when:
This is an example rule that blocks all script requests originating from "example.com" to any URL with "abc" as a substring:
The urlFilter field of a rule condition is used to specify the pattern matched against the request URL. See RuleCondition for details. Some examples of URL filters are:
| "abc" | https://abcd.com https://example.com/abcd |
https://ab.com |
| "abc*d" | https://abcd.com https://example.com/abcxyzd |
https://abc.com |
| "||a.example.com" | https://a.example.com/ https://b.a.example.com/xyz |
https://example.com/ |
| "|https*" | https://example.com | http://example.com/ http://https.com |
Rules are organized into rulesets:
Note: Errors and warnings about invalid static rules are only displayed during testing. Invalid static rules in permanently installed extensions are ignored. Therefore, it's important to verify that your static rulesets are valid by testing.
An extension can:
Note: The number of rules in enabled static rulesets for all extensions must not exceed the global limit. Extensions shouldn't depend on the global limit having a specific value; instead, they should use getAvailableStaticRuleCount to find the number of additional rules they can enable.
The number of dynamic and session-scoped rules an extension can add is limited to:
When the browser evaluates how to handle requests, it checks each extension's rules that have a condition that matches the request and chooses the one to consider applying as follows:
Note: When multiple matching rules have the same rule priority and rule action type, the outcome can be ambiguous when the matched action support additional properties. These properties can result in outcomes that cannot be combined. For example:
To control the order in which actions are applied, assign distinct priority values to rules whose order of precedence is important.
Note: After rule priority and rule action, Firefox considers the ruleset the rule belongs to, in this order of precedence: session > dynamic > static rulesets. This cannot be relied upon across browsers, see WECG issue 280.
If only one extension provides a rule for the request, that rule is applied. However, where more than one extension has a matching rule, the browser chooses the one to apply in this order of precedence:
If the request was not blocked or redirected, the matching modifyHeaders actions are applied, as documented in declarativeNetRequest.ModifyHeaderInfo.
testMatchOutcome, getMatchedRules, and onRuleMatchedDebug are available to assist with testing rules and rulesets. These APIs require the "declarativeNetRequestFeedback" permissions. In addition:
The response header to match for the request, declared in the rule.condition.excludedResponseHeaders array or rule.condition.responseHeaders array.
declarativeNetRequest.MatchedRuleDetails of a matched rule.
declarativeNetRequest.ModifyHeaderInfoThe request or response headers to modify for the request.
declarativeNetRequest.RedirectDetails of how the redirect should be performed. Only valid for redirect rules.
declarativeNetRequest.ResourceTypeThe resource type of a request.
declarativeNetRequest.RuleAn object containing details of a rule.
declarativeNetRequest.RuleActionAn object defining the action to take if a rule is matched.
declarativeNetRequest.RuleConditionAn object defining the condition under which a rule is triggered.
declarativeNetRequest.URLTransformAn object containing details of a URL transformation to perform for a redirect action.
Ruleset ID for the dynamic rules added by the extension.
declarativeNetRequest.GETMATCHEDRULES_QUOTA_INTERVALThe time interval within which declarativeNetRequest.MAX_GETMATCHEDRULES_CALLS_PER_INTERVAL declarativeNetRequest.getMatchedRules calls can be made.
declarativeNetRequest.GUARANTEED_MINIMUM_STATIC_RULESThe minimum number of static rules guaranteed to an extension across its enabled static rulesets.
declarativeNetRequest.MAX_GETMATCHEDRULES_CALLS_PER_INTERVALThe number of times declarativeNetRequest.getMatchedRules can be called within a period of declarativeNetRequest.GETMATCHEDRULES_QUOTA_INTERVAL.
declarativeNetRequest.MAX_NUMBER_OF_DISABLED_STATIC_RULESThe maximum number of static rules that can be disabled on each static ruleset.
declarativeNetRequest.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULESThe maximum number of dynamic and session-scoped rules an extension can add.
declarativeNetRequest.MAX_NUMBER_OF_DYNAMIC_RULESThe maximum number of dynamic rules an extension can add.
declarativeNetRequest.MAX_NUMBER_OF_ENABLED_STATIC_RULESETSThe maximum number of static rulesets an extension can enable.
declarativeNetRequest.MAX_NUMBER_OF_REGEX_RULESThe maximum number of regular expression rules that an extension can add.
declarativeNetRequest.MAX_NUMBER_OF_SESSION_RULESThe maximum number of session-scoped rules an extension can add.
declarativeNetRequest.MAX_NUMBER_OF_STATIC_RULESETSThe maximum number of static rulesets an extension can specify as part of the declarative_net_request.rule_resources manifest key.
declarativeNetRequest.SESSION_RULESET_IDThe ruleset ID for the session-scoped rules added by the extension.
Returns the number of static rules an extension can enable before the global static rule limit is reached.
declarativeNetRequest.getDisabledRuleIds()Returns the IDs of the disabled rules in a static ruleset.
declarativeNetRequest.getDynamicRules()Returns the set of dynamic rules for the extension.
declarativeNetRequest.getEnabledRulesets()Returns the IDs for the set of enabled static rulesets.
declarativeNetRequest.getMatchedRules()Returns all the rules matched for the extension.
declarativeNetRequest.getSessionRules()Returns the set of session-scoped rules for the extension.
declarativeNetRequest.isRegexSupported()Checks if a regular expression is supported as a declarativeNetRequest.RuleCondition.regexFilter rule condition.
declarativeNetRequest.setExtensionActionOptions()Configures how the action count for tabs are handled.
declarativeNetRequest.testMatchOutcome()Checks if any of the extension's declarativeNetRequest rules would match a hypothetical request.
declarativeNetRequest.updateDynamicRules()Modifies the active set of dynamic rules for the extension.
declarativeNetRequest.updateEnabledRulesets()Updates the set of active static rulesets for the extension.
declarativeNetRequest.updateSessionRules()Modifies the set of session-scoped rules for the extension.
declarativeNetRequest.updateStaticRules()Modifies the enabled state of rules in a static ruleset.
Fired when a rule is matched with a request when debugging an extension with the "declarativeNetRequestFeedback" permission.
Enable JavaScript to view this browser compatibility table.
This page was last modified on Feb 19, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.