Setting the socks proxy for a session


#1

Hi folks,

currently migrating a NWJS app into Electron and I like many of the little differences. But I am stuck with one and hope you may help: I try to set the socks5 proxy for a session:

Getting the session for this window:

var sess = require('remote').getCurrentWebContents().session;

and then setting the proxy like:

var mySocks = "socks5://"+socksIp+":1080";
sess.setProxy({pacScript:"", proxyRules:mySocks},myNextFunction());

as I read up on

Now that spawns an error and I am stuck… what I am not seeing?

Uncaught Error: Could not call remote function `setProxy`. Check that the function signature is correct. Underlying error: Error processing argument 0.
Error: Could not call remote function `setProxy`. Check that the function signature is correct. Underlying error: Error processing argument 0.
    at callFunction (/Users/puzzler/electron-v0.36.7-darwin-x64/Electron.app/Contents/Resources/atom.asar/browser/lib/rpc-server.js:203:11)
    at EventEmitter.<anonymous> (/Users/puzzler/electron-v0.36.7-darwin-x64/Electron.app/Contents/Resources/atom.asar/browser/lib/rpc-server.js:293:12)
    at emitMany (events.js:108:13)
    at EventEmitter.emit (events.js:182:7)
    at EventEmitter.<anonymous> (/Users/puzzler/electron-v0.36.7-darwin-x64/Electron.app/Contents/Resources/atom.asar/browser/api/lib/web-contents.js:130:25)
    at emitTwo (events.js:87:13)
    at EventEmitter.emit (events.js:172:7)

Thanks,
Ralf


#2

As stated in the http://electron.atom.io/docs/api/session/#sessetproxyconfig-callback, when the pacScript is set, the proxyRules are ignored.

instead of doing
sess.setProxy({pacScript:"", proxyRules:mySocks},myNextFunction());
you can remove the pacScript and make it like
sess.setProxy({proxyRules:mySocks},myNextFunction());

Hope it might help you.