Electron-based app using system proxy settings


#1

My app uses require(‘http’) to download files in the background while the chrome-based UI is presented to the user. If the user has a proxy server set up globally on their machine (for example, on a Mac in System Preferences > Network > Advanced… > Proxy if they have the URL of a .pac file set up), the browser part just works. Chrome detects the system proxy and uses it. But my http downloads don’t.

Is there any way to convince node’s http or https modules to obey the global system proxy settings? I’ve googled like crazy and I can’t find any solution.

(I found app.commandLine.appendSwitch(‘proxy-pac-url’, ‘http://blah-blah-blah/pac.pac’) but that only changes the browser, it doesn’t impact the node stuff; and I don’t need that since the browser is using the system settings correctly anyway.)


#2

Did you see this post on StackOverflow? The author also wrote a blog post about this: http://geekswithblogs.net/shaunxu/archive/2013/09/05/semi-global-proxy-setting-for-node.js.aspx

Maybe this will help you!


#3

I did see those, but unfortunately they would require that my application somehow know what proxy server to use. The whole point of having a system-wide proxy setting in the O/S preferences panel is that you don’t need individual apps to have to be configured with the proxy addresses. If I knew the proxy server address, I could just pass it in the first argument of the http.get call. But my users are not at all sophisticated, so expecting them to do proxy setup manually is unrealistic.

It’s frustrating, because the Chrome part of the app works just fine. Chrome knows how to read and use system-wide settings, but Node apparently doesn’t.


#4

I found a work-around. If my direct http/https connections don’t work, I instead use mainWindow.webContents.downloadURL(url);
and let the browser do the downloading on my behalf, since it understands how to use the system-wide proxy settings.