Hello,
I'm trying to modify response headers but somehow they do not get modified.
However, request headers are modified accordingly.
Am I missing something? According to the documentation both request or response headers can be modified.
My demo code:
Manifest.json
{
"manifest_version": 3,
"name": "AddHeader Mv3",
"description": "Proof of concept of an extension adding headers",
"version": "0.0.1",
"permissions": [
"declarativeNetRequest"
],
"host_permissions": [
],
"background": {
"service_worker": "background.js"
}
}
background.js:
chrome.declarativeNetRequest.getDynamicRules(function(rules) {
var ruleIdx = 0;
var existingRules = [];
for (var i=0;i<rules.length;i++) {
ruleIdx = rules[i].id;
existingRules.push(rules[i].id);
}
ruleIdx++;
chrome.declarativeNetRequest.updateDynamicRules({
addRules:
[
{
action: {
type: "modifyHeaders",
requestHeaders: [{"header": "extension-add-1", "operation": "set", "value": "requestedheader-added"}],
responseHeaders: [{"header": "extension-add-2", "operation": "set", "value": "responseheader-added"}]
},
condition: {"regexFilter": "^https://sports\.yahoo\.com(.*)$", "resourceTypes": ["main_frame"]}, id: ruleIdx,
priority: 1
},
],
removeRuleIds: existingRules
});
});
In this demo when I visit sports.yahoo.com site, I can see my request header is added. But the response header is not.
Thanks for any pointers!
Francois