Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
Our application needs to supports web proxies. It also needs to open WebSocket connections from the main process.
The natural choice would be the net module "uses Chromium's native networking library instead of the Node.js implementation, offering better support for web proxies." However, it only supports HTTP(S) requests; not WebSocket.
Proposed Solution
The net module should expose Chromium's WebSocket implementation like this:
const { net } = require('electron')
new net.WebSocket(...)Alternatives Considered
I have been unable to find any alternative implementation that lets us open WebSocket connections from the main process and support all web proxies. I would also appreciate any advice on alternatives to the Electron net module.
I found https://github.com/jfromaniello/mac-ca and https://github.com/ukoloff/win-ca, but
- They are OS-specific. I would like to support all platforms supported by Electron.
- It's unclear to me whether this supports all web proxies. Is the only significant difference between the Node.js and Chromium network stacks their list of root CAs?
Additional Information
I found this previous issue which is very similar. It was closed because "it will take a considerable amount of work since the net layer of chromium doesn't expose it directly as a part of URLRequest." 7.5 years later, perhaps this has changed?
Activity
felixrieseberg commentedon Jan 13, 2025
I think this is a pretty reasonable idea - and if it could be done without increasing complexity dramatically, we might be able to take a PR. Would you be interested in writing one?
jameshfisher commentedon Jan 19, 2025
I don't know the Electron codebase but I've had a look around:
net.requestis implemented in/lib/browser/api/net.tsusingClientRequestClientRequestis implemented in/lib/common/api/net-client-request.tsusingcreateURLLoaderfromprocess._linkedBinding('electron_common_net')electron_common_netandcreateURLLoaderare defined in/shell/common/api/electron_api_net.ccusingSimpleURLLoaderWrapperSimpleURLLoaderWrapperis implemented in/shell/common/api/electron_api_url_loader.ccusingnetwork::SimpleURLLoaderfromservices/network/public/cpp/simple_url_loader.hsimple_url_loader.his from Chromium?Not sure where Chromium's WebSocket implementation would be exposed for us to use, but I see files like
services/network/websocket_factory.ccenniomariani commentedon Dec 8, 2025
If you haven't found a solution yet:
https://github.com/TooTallNate/proxy-agents/tree/main/packages/socks-proxy-agent