Dynamically modify header with DNR

152 views
Skip to first unread message

Shulamit Sompo

unread,
Dec 26, 2023, 6:29:55 AM12/26/23
to Chromium Extensions
Hi.

I need to modify a response header for any fetch call that contains Set-Cookie in the response header.
I need to take the original value and set a new value that will be a manipulation of the original value.

For example (it is a more complex implementation, it is just an example):
Original header: Set-Cookie: authToken = aaa
New header: Set-Cookie: authToken = ababab

Is there a way to do it on manifest V3 with DNR (there I see just static data as value) or any other way?

Thanks!

wOxxOm

unread,
Dec 26, 2023, 9:15:03 AM12/26/23
to Chromium Extensions, Shulamit Sompo
Until https://crbug.com/1141166 is fixed, the only solution is to use webRequestBlocking in ManifestV2 or force-installed ManifestV3 extensions or in a patched Chrome binary.

שולמית סומפולינסקי

unread,
Dec 28, 2023, 10:31:00 AM12/28/23
to Chromium Extensions, wOxxOm, Shulamit Sompo
In addition to the issue of creating a condition based on a request/response header,
Is there a way for the value to be based on the previous value, and to know what domain the rule is working on now
Like in the getMewCookieValue function below
Or any other way that I can intercept any request and change the cookies

Thanks!!

chrome.declarativeNetRequest.updateDynamicRules({
addRules: [ {
id: 1,
priority: 1,
action: {
type: chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS,
responseHeaders: [
{
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
header: 'Set-Cookie',
value: this.getMewCookieValue(currentCookieValue, cookieDomain),
},
]
},
condition: {
urlFilter: '*'
}
}],
removeRuleIds: [1]
});

ב-יום שלישי, 26 בדצמבר 2023 בשעה 16:15:03 UTC+2, wOxxOm כתב/ה:
Reply all
Reply to author
Forward
0 new messages