I'm currently trying to figure out when exactly chrome applies the declarativeNetRequest
rules, specifically HeaderOperation.REMOVE
.
For testing this, I'm using the following setup:
Extension A that (using webRequests
) logs all headers received:
chrome.webRequest.onHeadersReceived.addListener(
(details) => {
console.log(`Headers for ${details.url}:`);
details.responseHeaders.forEach(header => {
console.log(`${header.name}: ${header.value}`);
});
},
{ urls: ["<all_urls>"] },
["responseHeaders"]
);
Extension B that (using declarativeNetRequest
) removes some headers:
const allResourceTypes = Object.values(chrome.declarativeNetRequest.ResourceType);
const rules = [
{
id: 1,
priority: 1,
action: {
type: chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS,
responseHeaders: [
{
operation: chrome.declarativeNetRequest.HeaderOperation.REMOVE,
header: 'header-name',
},
]
},
condition: {
urlFilter: "|http*://*/*",
resourceTypes: allResourceTypes,
}
}
];
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: rules.map((rule) => rule.id), // remove existing rules
addRules: rules
});
Now I would expect this to remove all headers of type header-name
(and this header to not be logged by Extension A).
What I'm getting however, are two somewhat contradictory results:
- When using Testheaders, the headers seem to be removed successfully (I tested it with
cf-ray
, which is a header returned by cloudflare). - Extension A however, still prints out those headers.
Does this mean that, even when headers are removed by an extension, other extensions are still always able to see all of the original headers?
I'm looking for an answer on what the intended behaviour would be, as well as the relevant part of the documentation.