From 67bc969a0b3bd3a75fa1d6cd7dcf316be9ec37e9 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Fri, 30 Aug 2024 09:57:58 -0400 Subject: [PATCH 1/2] Add new declarativeNetRequest RuleConditions --- .../declarativenetrequest/headerinfo/index.md | 66 +++++++++++++++++++ .../rulecondition/index.md | 4 ++ 2 files changed, 70 insertions(+) create mode 100644 files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/headerinfo/index.md diff --git a/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/headerinfo/index.md b/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/headerinfo/index.md new file mode 100644 index 000000000000000..3a327eb41018917 --- /dev/null +++ b/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/headerinfo/index.md @@ -0,0 +1,66 @@ +--- +title: declarativeNetRequest.HeaderInfo +slug: Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest/HeaderInfo +page-type: webextension-api-type +browser-compat: + - webextensions.api.declarativeNetRequest.RuleCondition.responseHeaders + - webextensions.api.declarativeNetRequest.RuleCondition.excludedResponseHeaders +--- + +{{AddonSidebar}} + +The response header to match for the request, declared in the {{WebExtAPIRef("declarativeNetRequest.RuleCondition", "rule.condition")}}`.excludedResponseHeaders` array or {{WebExtAPIRef("declarativeNetRequest.RuleCondition", "rule.condition")}}`.responseHeaders` array. + +When used in the condition responseHeaders, the rule matches if the request matches this response header condition. When used in the condition excludedResponseHeaders, the rule does not match if the request matches this response header condition. + +Each object describes one header to match or exclude. To check multiple headers, multiple objects can be specified in these arrays, or across multiple rules. + +## Type + +Values of this type are objects. They contain these properties: + +- `header` + - : A `string`. The name of the header. This condition matches on the name only if both values and excludedValues are not specified. +- `values` {{optional_inline}} + - : An array of `string`. If specified, this condition matches if the header's value matches at least one pattern in this list. This supports case-insensitive header value matching plus the following constructs: + - `'*'` : Matches any number of characters. + - `'?'` : Matches zero or one character(s). + - `'*'` and `'?'` can be escaped with a backslash, e.g. `'\*'` and `'\?'`. +- `excludedValues` {{optional_inline}} + - : An array of `string`. If specified, this condition is not matched if the header exists but its value contains at least one element in this list. This uses the same match pattern syntax as `values`. + +{{WebExtExamples("h2")}} + +## Browser compatibility + +{{Compat}} + + diff --git a/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/rulecondition/index.md b/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/rulecondition/index.md index 44b738992f06a82..3d0a334da13959f 100644 --- a/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/rulecondition/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/rulecondition/index.md @@ -42,6 +42,10 @@ Values of this type are objects. They contain these properties: - : An array of {{WebExtAPIRef("declarativeNetRequest.ResourceType")}}. List of resource types that the rule matches with. An empty list is not allowed. This must be specified for `"allowAllRequests"` rules and may only include the `"sub_frame"` and `"main_frame"` resource types. - `excludedResourceTypes` {{optional_inline}} - : An array of {{WebExtAPIRef("declarativeNetRequest.ResourceType")}}. List of resource types that the rule does not match on. Only one of [`resourceTypes`](#resourcetypes) and `excludedResourceTypes` should be specified. If neither of them is specified, all resource types except `"main_frame"` are blocked. +- `responseHeaders` {{optional_inline}} + - : An array of {{WebExtAPIRef("declarativeNetRequest.HeaderInfo")}}. The rule matches if the request matches any response header condition in this list (if specified). +- `excludedResponseHeaders` {{optional_inline}} + - : An array of {{WebExtAPIRef("declarativeNetRequest.HeaderInfo")}}. The rule does not match if the request matches any response header condition in this list (if specified). If both `excludedResponseHeaders` and `responseHeaders` are specified, then the `excludedResponseHeaders` property takes precedence. - `tabIds` {{optional_inline}} - : An array of `number`. List of {{WebExtAPIRef("tabs.Tab")}}.`id` that the rule should match. An ID of {{WebExtAPIRef("tabs.TAB_ID_NONE")}} matches requests that don't originate from a tab. An empty list is not allowed. Only supported for session-scoped rules. - `excludedTabIds` {{optional_inline}} From c8185e51722aeb449a6321702f1fc63fb502f755 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Wed, 25 Sep 2024 11:27:39 -0400 Subject: [PATCH 2/2] Make suggested changes to page about declarativeNetRequest HeaderInfo --- .../api/declarativenetrequest/headerinfo/index.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/headerinfo/index.md b/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/headerinfo/index.md index 3a327eb41018917..e00e70cace372cd 100644 --- a/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/headerinfo/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/api/declarativenetrequest/headerinfo/index.md @@ -9,12 +9,14 @@ browser-compat: {{AddonSidebar}} -The response header to match for the request, declared in the {{WebExtAPIRef("declarativeNetRequest.RuleCondition", "rule.condition")}}`.excludedResponseHeaders` array or {{WebExtAPIRef("declarativeNetRequest.RuleCondition", "rule.condition")}}`.responseHeaders` array. +The response header to match for the request, declared in the {{WebExtAPIRef("declarativeNetRequest.RuleCondition", "rule.condition")}}`.excludedResponseHeaders` array or {{WebExtAPIRef("declarativeNetRequest.RuleCondition", "rule.condition")}}`.responseHeaders` array. If specified, the array must be non-empty. When used in the condition responseHeaders, the rule matches if the request matches this response header condition. When used in the condition excludedResponseHeaders, the rule does not match if the request matches this response header condition. Each object describes one header to match or exclude. To check multiple headers, multiple objects can be specified in these arrays, or across multiple rules. +> [!NOTE] Matching by headers is a relatively new feature. Make sure to feature-detect its availability before relying on it. While some browsers ignore the complete rule when an unrecognized condition is present, Chrome 121 until 127 applied the whole rule while ignoring the `responseHeaders` condition. This could result in matching more requests than intended, see [Chromium issue 347186592](https://issues.chromium.org/issues/347186592). + ## Type Values of this type are objects. They contain these properties: @@ -27,7 +29,7 @@ Values of this type are objects. They contain these properties: - `'?'` : Matches zero or one character(s). - `'*'` and `'?'` can be escaped with a backslash, e.g. `'\*'` and `'\?'`. - `excludedValues` {{optional_inline}} - - : An array of `string`. If specified, this condition is not matched if the header exists but its value contains at least one element in this list. This uses the same match pattern syntax as `values`. + - : An array of `string`. If specified, this condition is not matched if the header exists but its value contains at least one element in this list. This uses the same glob pattern syntax as `values`. If `values` and `excludedValues` are both matched, then `excludedValues` takes precedence. {{WebExtExamples("h2")}}