Feedbacks on declarativeNetRequest migration

129 views
Skip to first unread message

Hao Nguyen

unread,
Nov 1, 2022, 11:31:00 AM11/1/22
to Chromium Extensions
Hi,

So we have been trying to migrate ModHeader (https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj) to MV3. ModHeader relies very heavily on WebRequest blocking API, so it has been a daunting task to do this migration. Here are some issues that we have encountered during the migration.

1, ModHeader allows users to modify individual cookie in the cookie request header. This requires us to unpack the cookie request header, parse its value, and modify only a part of it. There is no equivalent API in DNR. I tried looking into the debugger API with Fetch domain. That too, did not work out properly, as the cookie header modification is ignored (https://bugs.chromium.org/p/chromium/issues/detail?id=1200844)

2, ModHeader also allows users to modify individual set-cookie response header. This requires us to parse all the set-cookie response headers to find the matching cookie-name, then modify its value/attributes. There is no equivalent API in DNR either. Again, I tried looking into the debugger API with Fetch domain. That too, did not work out properly as set-cookie response header modification is also ignored (https://bugs.chromium.org/p/chromium/issues/detail?id=1200844)

3, Operation: 'append' does not work (https://bugs.chromium.org/p/chromium/issues/detail?id=1117475). In ModHeader, we allow users to append a request header value to an existing request header with the same name. I thought that is what the operation: 'append' mode would do. It does not work. Instead operation 'append' generates a cryptic error message like "Rule with id 1 must not specify a request header to be appended." ModHeader also support appending to existing request header with a comma in between. That way users can toggle request headers like ExperimentA,ExperimentB,ExperimentC. There is no equivalent append with comma operation in DNR.

4, Regex filters and exclude regex filters - ModHeader allows users to specify a list of regex filters + exclude regex filters. Unfortunately DNR only supports a single regex filter. Trying to combine a list of regex filters + a list of exclude regex filters into a single regex expression is extremely hard. If DNR conditions can be composite (like a condition can contain an "and" list and an "or" list of condition), then we can express more complex conditions like
condition: { 
  and: [
    { and: [ { regexFilter: regex1 }, { regexFilter: regex2 } ] },
    { or: [ { regexFilter: regex3 }, { regexFilter: regex4 } ] },
  ]
}

5, ModHeader supports some simple string substitution at runtime, like {{uuid}} would generate a random UUID each time it is evaluated, or {{timestamp}} would be substituted with the current timestamp in milliseconds, or {{url_path}} would be replaced with the request URL's path. DNR does not allow that.

We hope that the Chromium team will listen to feedbacks and make the DNR API more powerful.

Thanks,
Hao

wOxxOm

unread,
Nov 1, 2022, 6:46:17 PM11/1/22
to Chromium Extensions, hao...@gmail.com
Extensions like yours were doomed since the very first day ManifestV3 was announced and we saw that webRequestBlocking is removed from non-enforced extensions. It was also clear that no advanced processing will ever be added to declarativeNetRequest because it would require adding some scripting language and that is not declarative.

That said, some improvements for processing cookies or CSP and other popular things may be added in the future but don't expect it to happen soon - ManifestV3 team is inadequately tiny and no one has been working on this API for the most part of the year. Still, you should file a feature request on https://crbug.com and cross-post it in https://github.com/w3c/webextensions/issues/ where more people would see it and possibly help design the API.

Re #3, seems to be already fixed in Chrome Canary.
Re #4, maybe you can add another rule with a different "priority" + "allow" or "allowAllRequests", maybe even a cascade of such rules?

Vaibhav Nigam

unread,
Nov 4, 2022, 1:42:50 AM11/4/22
to Chromium Extensions, wOxxOm, hao...@gmail.com
Re #4 - I also feel the need of exclusion regex as combining everything in the regexFilter makes the group capturing and regexSubstitution very complex.

@wOxxOm - I don't find enough documentation on "allow" and "allowAllRequests" options. Can you please help with an example on how these options can solve exclusion regex need?

Thanks,
Vaibhav

Reply all
Reply to author
Forward
0 new messages