Manifest V3 - Intercept request in flight

226 views
Skip to first unread message

Rahul Raman

unread,
Feb 17, 2025, 6:32:43 AMFeb 17
to Chromium Extensions
How can we intercept request in manifest v3 in flight ?

I tried using declarativeNetRequest updateDynamicRule() for modifying request headers, but the rules needs to be created beforehand for it to get applied to a request.
If we try to create the rule while listening to a request using the webRequest methods, the rule doesn't get applied to that current ongoing request.

So how can we add dynamic values to the header in an ongoing request ?

Rahul Raman

unread,
Feb 19, 2025, 3:08:11 AMFeb 19
to Chromium Extensions, Rahul Raman
Any solution for this issue ?

Oliver Dunk

unread,
Feb 19, 2025, 4:53:24 AMFeb 19
to Rahul Raman, Chromium Extensions
Hi Rahul,

I'm afraid that adding dynamic headers isn't currently something the API supports.

If you could share more about why you're looking to add them, we might be able to provide some suggestions.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/fb964a86-0704-4d48-9c2a-385ecc1d6521n%40chromium.org.
Message has been deleted

Rahul Raman

unread,
Feb 20, 2025, 7:23:59 AMFeb 20
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Rahul Raman
Hello Oliver

Our use-case is something like this -

When a certain login request is made
1. We need to use the header value of that request to get some token (using native-messaging) - We are doing this inside webRequest methods.
2. Then we need to add "Authorization":"token" in the request header of that ongoing request so that the request becomes successful.

So how can we add this dynamic header value to the ongoing request ?

Oliver Dunk

unread,
Feb 20, 2025, 8:21:23 AMFeb 20
to Rahul Raman, Chromium Extensions
If there is a native component, have you considered setting up a proxy instead of using an extension?

Unfortunately, I do think your use case is one that isn't solvable using what we have today as we are explicitly moving away from allowing code to run in the blocking path of a web request.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

Rahul Raman

unread,
Feb 20, 2025, 9:32:22 AMFeb 20
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Rahul Raman

No actually we have to intercept an ongoing request in browser and add things to its header, so creating extension for that.

So this flow was achievable in manifest v2 using webRequestBlocking, right ? 
We cannot use v2 post June 2025, or we can ? say at enterprise level ?

Oliver Dunk

unread,
Feb 21, 2025, 11:18:06 AMFeb 21
to Rahul Raman, Chromium Extensions
If you had a native proxy, you could configure traffic from the browser to go through the proxy and you would be able to modify requests as needed. I would definitely encourage you to look at this as it could work well.

Even in Manifest V2, we required a blocking webRequest listener to make a decision synchronously. This means we never officially supported speaking to an external service before deciding how to modify or cancel a request. That said, some developers used the XMLHTTPRequest API which does run synchronously and could be used to make a network request to a third-party service.

Manifest V2 will eventually no longer be available - the timeline for enterprise deprecation is June 2025. That said, for extensions installed by policy you can still use the blocking variant of webRequest in Manifest V3. You cannot however use XMLHTTPRequest which does mean that unfortunately your use case is not easily solved right now.

I hope that all makes sense.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

Rahul Raman

unread,
Feb 23, 2025, 2:03:36 AMFeb 23
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Rahul Raman
Yes it does, thanks for this.

So to summarise
1. If for an ongoing request i want to fetch some value by using native messaging concept and then add the value in the header of that ongoing request - this flow is not directly achievable in manifest v3 ?

2. For using native proxy as you suggested, will it be like this ? - extension redirects a request to the proxy and proxy makes the request again for us ? Can you give more details about this or maybe some reference which can be followed. ?

Thanks.

Oliver Dunk

unread,
Feb 24, 2025, 5:12:09 AMFeb 24
to Rahul Raman, Chromium Extensions
If for an ongoing request i want to fetch some value by using native messaging concept and then add the value in the header of that ongoing request - this flow is not directly achievable in manifest v3

Yes. In fact, this is not possible in both Manifest V2 and Manifest V3.

For using native proxy as you suggested, will it be like this ? - extension redirects a request to the proxy and proxy makes the request again for us ? Can you give more details about this or maybe some reference which can be followed.

Not quite. You wouldn't need an extension at all, but could instead update your system's proxy settings:
  1. Paste chrome://settings/system into the address bar.
  2. Hit enter.
  3. Click "Open your computer's proxy settings".
This could directly tell the system to send network traffic through the extension.

If you need more control, then an extension might make sense - the chrome.proxy API lets you change proxy settings including making only certain requests go through a proxy.

Unfortunately I don't have documentation for this, but you should be able to follow non extension-specific guidance for setting up proxies. You are right that the proxy would likely be making the request again with the updates headers.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB
Reply all
Reply to author
Forward
0 new messages