How to control requests to a proxy

209 views
Skip to first unread message

Taro Crown

unread,
Jun 13, 2023, 7:31:46 AM6/13/23
to Chromium Extensions
I am looking to develop an extension to control HTTP requests.
I use the chrome.proxy API to set up a proxy and control user browsing.
However, we would like to have the following requests communicate directly without going through the proxy.
  • Requests with specific extensions (".css", ".jpeg", etc.)
  • Requests of a specific type ("script", "image", etc.)

I thought I could achieve this with proxy.onRequest(), but Chrome does not seem to support it.
proxy.onRequest - Mozilla | MDN
Any ideas on how to communicate without going through a proxy for certain requests?

Deco

unread,
Jun 13, 2023, 2:34:55 PM6/13/23
to Taro Crown, Chromium Extensions
What you are trying to do is I would regard as esoteric? given that you will naturally filter through all the HTTP requests through the proxy. However it's not impossible, you can use ProxyConfig's mode, specifically the direct to have connections be made bypassing the proxy. Be aware however that on an initial read this will require heavy manual implementation logic of your own for actually handling the switching and content filter, you will definitely need webRequest to handle this.

Cheers,
Deco

Oliver Dunk

unread,
Jun 14, 2023, 6:37:28 AM6/14/23
to Taro Crown, Chromium Extensions
Hi Taro,

Would a PAC script help here?


I haven't had a chance to work with these much, but I believe you can take a URL and provide a JS function to decide what proxy each requests go through.
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 on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/810d46f5-98ea-4316-bbff-ed21fe5a0e67n%40chromium.org.

Taro Crown

unread,
Jun 14, 2023, 7:27:02 AM6/14/23
to Chromium Extensions, Deco, Chromium Extensions, Taro Crown
Thanks for your answer!
I have written code to dynamically control proxy settings with the webRequestBlocking.
The code catches the request onBeforeRequest and sets the mode to "DIRECT" if the request has a specific extension.
However, since chrome.proxy.settings.set is an asynchronous function, the request will proceed while the settings are being changed.
Is it difficult to control this?
Or am I missing some other way?

2023年6月14日水曜日 3:34:55 UTC+9 Deco:

Taro Crown

unread,
Jun 14, 2023, 7:28:07 AM6/14/23
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Taro Crown
Hello Oliver.

I have considered using the PAC script, but for HTTPS requests, the URL is omitted and the extension cannot be checked.
I am also aware that unlike webRequest, it is not possible to retrieve the type of request.
Therefore, I have concluded that it is difficult to control this with a PAC script.
If you have any ideas, please let me know.

2023年6月14日水曜日 19:37:28 UTC+9 Oliver Dunk:

Deco

unread,
Jun 14, 2023, 7:38:31 AM6/14/23
to Taro Crown, Chromium Extensions
That is correct, and why your problem is rather esoteric. Due to it being async you will need to handle this manually to stop the request being processed while the settings are changed (this is what i was referring to with requiring heavy manual implementation logic to do what you are requiring).

As an idea you will need to maintain a queue of the pending requests and process them one at a time, to ensure that the proxy settings correctly update before each request is made, be aware however that this is pretty terrible for scaling simultaneous large scale connections, so if you plan to use this for any your specific files constantly switching, it is not a viable solution due to the performance degradation.

I don't have any other way you could feasibly go about what you are trying to do in a way which is efficient as Chrome doesn't support the easy solution of proxy.onRequest, but i hope it was useful for thinking about what you require to do.

Cheers,
Deco

Oliver Dunk

unread,
Jun 14, 2023, 8:10:09 AM6/14/23
to Deco, Taro Crown, Chromium Extensions
I have considered using the PAC script, but for HTTPS requests, the URL is omitted and the extension cannot be checked.

Ah, TIL!

Unfortunately I can't immediately think of any solutions for this.

If you want to share your use case, that would at least be helpful to know what you'd like to be able to do in the future :)

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.

Taro Crown

unread,
Jun 15, 2023, 10:13:49 PM6/15/23
to Chromium Extensions, Oliver Dunk, Taro Crown, Chromium Extensions, Deco
Hi all.
I have tried based on your advice and found it very difficult to implement this in a Chrome extension.
I will look into it again to see if I can develop an extension using a different approach.
Thank you very much for your response.

2023年6月14日水曜日 21:10:09 UTC+9 Oliver Dunk:
Reply all
Reply to author
Forward
0 new messages