1

As the title suggests, I'm working on an ElectronJS project where I have multiple BrowserView objects and would like to use a different proxy for each window.

I read here that ses.setProxy() exists, implying I could perhaps use browserViewObj.webContents.session.setProxy() to use a particular proxy. However, the question still remains: How could I authenticate it?

Permittivity
  • 229
  • 1
  • 12

2 Answers2

1

I am doing the exact same thing right now and the answer is, yes you can. The webcontents object of the BrowserView has a login event that you can capture and login into your proxy using that event.

Refer here

https://www.electronjs.org/docs/latest/api/web-contents#event-login

Cyril Gupta
  • 13,505
  • 11
  • 64
  • 87
0

UPDATE: As the above answer says, it looks like there is a way to intercept the login, detect when it is a proxy, and give the auth details there. I'll leave my original answer, for the background links I found (plus I've not personally tested the proxy auth will work).


I think the answer is "You can't, by design". You give a PAC file to setProxy() (or use proxyRules, but that just offers the same options). It seems that they specifically don't allow username/password in PAC files for security. (Though that logic doesn't really apply to using proxyRules directly, does it.)

This answer suggests setting up an ssh tunnel. You could pre-create one tunnel (one port) for each of your BrowserView objects, and then set localhost and the desired port as the proxy.

The chosen answer on the first link above suggests https://github.com/sjitech/proxy-login-automator which looks like it might that same idea. It seems to be a commandline script, but you should be able to pull out the bits you need and run it in the Electron main process.

Darren Cook
  • 27,837
  • 13
  • 117
  • 217
  • Thank you for the response! However, (correct me if I'm wrong) I believe these solutions require proxies which conform to the SOCKS protocol. Unfortunately, the proxies I am using only conform to the HTTP/HTTPS protocols. Is there any workaround in my case? My current solution is to use puppeteer with a number of chromium windows open. However, having 15+ chromium windows in my tool bar doesn't look very nice (plus I was hoping to be able to show previews of each each screen in one BrowserWindow object). – Permittivity Dec 30 '19 at 14:14
  • @Permittivity Have you tried the `http://username:password@example.com/` style of specifying a URL? It might work, worth a try. – Darren Cook Dec 30 '19 at 17:18