Hi,
I have a question for setting headers by DNR, looking at the redirect action, we can use regexSubstitution, can we use similar approach for setting headers, like
chrome.declarativeNetRequest.updateSessionRules({
removeRuleIds: ['one-good-rule'],
addRules: [{
id: 'one-good-rule',
action: {
type: 'modifyHeaders',
requestHeaders: [
{ header: 'my-domain-test', operation: 'set', value: '\\1' },
]
},
condition: {
regexFilter: '^(.*)/my/specific/path',
resourceTypes: ['xmlhttprequest'],
}
}]
})
I tried it, but it doesn't work. But this would be very helpful since the static rules would be verbose to update, and not flexible.
For example, if the domain is dynamic, then I can not set the header, I think can workaround it by keep adding session rules of fixed domains, like
var sessionRuleCount = get all sessions rules count
chrome.declarativeNetRequest.updateSessionRules({
addRules: [{
id: sessionRuleCount + 1,
action: {
type: 'modifyHeaders',
requestHeaders: [
]
},
condition: {
resourceTypes: ['xmlhttprequest'],
}
}]
})
However, the session rules has maximum number, the regex approach looks very neat if it works
I would be very appreciated for any ideas or suggestions, Thank you!