Intercept HTTP(s) calls and modify them on the fly

41 views
Skip to first unread message

Newbie

unread,
Sep 16, 2023, 8:21:39 AM9/16/23
to nw.js
Hi guys,

I'm new to NW.js, please bear with me.

I'd like to know if NW is capable of handling these 02 uses case:
1. GET
1. let's say I'd like to load a web page, be it: https://www.wikipedia.org/
2. a NW handler will intercept that URL before it's even sent on the wire:
2.1. the URL is rewritten to my local proxy:
GET http://localhost:8000/https://www.wikipedia.org/ 1.1\r\n
X-MY-PROXY-HEADER: some_value_here\r\n
[...] I don't touch the original HTTP request headers and keep them as they were
...

2. POST
Same logic for post requests. I intercept a POST query:
POST http://localhost:8000/https://reqbin.com/post-online/ 1.1\r\n
X-MY-PROXY-HEADER: some_other_here\r\n
[...] I don't touch the original HTTP request headers and keep them as they were
...
<POST BODY>

Is this doable in NW.js? If yes, please point me to the corresponding doc or any code snippet.

Help appreciated
Thanks

russell....@gmail.com

unread,
Sep 16, 2023, 1:21:01 PM9/16/23
to nw.js
I've not tried it. I've only had to do single site reverse proxies with NWjs in the past.

I think the easiest way is to run a real custom localhost proxy server with custom certificate authority set. Set NW to use that proxy, and then do whatever it is you want to do with that.


There is also the --proxy-server chromium command line argument.
For CA:

Roger Wang

unread,
Sep 16, 2023, 5:08:00 PM9/16/23
to nw.js

--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nwjs-general/ebe4ee86-17af-47e6-8487-e28c164a5f24n%40googlegroups.com.

nw.js

unread,
Sep 18, 2023, 3:01:05 PM9/18/23
to nw.js
Thanks for the WebRequest link. I've built a small prototype but it seems not all requests are intercepted by the webRequest.onBeforeRequest listener. Some leaked and weren't sent to the listener (from Network inspector).
Furthermore, I found no way but to cancel the request first, then force a redirection. There's no direct way to change the destination URL on the fly.
Reply all
Reply to author
Forward
0 new messages