Configure a SOCKS5 Proxy for One Electron Session
Configure a dedicated Electron session before creating its window and account for reused connections and SOCKS authentication limitations.
After Electron's application-ready stage, configure the session that the window will actually use:
const proxySession = session.fromPartition('persist:proxy-work');
await proxySession.setProxy({
mode: 'fixed_servers',
proxyRules: 'socks5://127.0.0.1:1080'
});
const window = new BrowserWindow({
webPreferences: { session: proxySession }
});
Use the application's existing imports/lifecycle. This window's requests use proxySession; arbitrary Node clients and other partitions do not inherit it. For permitted public browsing, the SOCKS5 proxy list offers endpoint candidates; select one requiring no SOCKS account for Chromium's supported path.
For an already used session, decide what to do with pooled connections. Electron documents closeAllConnections() where an old route could otherwise remain; invoking it can interrupt ongoing work. A settings update does not move existing sockets.
Use resolveProxy for the actual URL to inspect selection. Confirm connection/exit separately, including bypasses and independently configured sessions.
Chromium's SOCKS5 implementation lacks SOCKS authentication-method support. HTTP login callbacks and a password in the URL do not add it. For a credential-requiring service, use a documented compatible arrangement instead of removing authentication from a shared listener.