How to set proxy for each webview tag in electronjs


Hello for all
I am creating simple app using Electron.
in my app, each webview tag load each URL.
My case is I need to set proxy different for each webview tag
please help me ,how to do it.
thank you!



If you want to set proxy for different web view check this [I didn’t tested this]

If you to set different proxy for different URL then check below code, you can use proxy.pac file


const {app, BrowserWindow} = require('electron');
const {session} = require('electron')
let mainWindow;
app.on('window-all-closed', function() {

  app.on('ready', function() {
  mainWindow = new BrowserWindow({width: 1024, height: 768 });
  session.defaultSession.allowNTLMCredentialsForDomains('*')//to access internal sites

var myVar = setInterval(myTimer, 3000);
function myTimer() {
   mainWindow.webContents.session.setProxy({pacScript:'file://' + __dirname + '/proxy.pac'}, function () {return true;});

mainWindow.webContents.session.setProxy({pacScript:'file://' + __dirname + '/proxy.pac'}, function () {mainWindow.loadURL('file://' + __dirname + '/browser.html');});


function FindProxyForURL(url, host) {

   if (shExpMatch(url, "*google*"))
         return "PROXY";

   if (shExpMatch(url, "*amazon*"))
         return "PROXY";
   return "DIRECT";

When ever you modify proxy.pac file it will automatically reflected in your electron app/webview


thank you very much.
same the link above : "You can assign a different session for the webview using the partition attribute and set proxy using session#setProxy api."
if you test it, could you please share it here for me refer?
thank you

example webview:
<webview id="wv1" src="" partition="persist:github"></webview> <webview id="wv2" src="" partition="electron"></webview>


i also creating app assignment help and i need to add each webview tag load each URL.

Thanks for this link @myfrndjk.


@davidsmith150 : I happy that i helped you :slight_smile: .If you tested the solution which is provided in that link please share the code to @lamxuanquyen .My use case has changed so I didn’t tested that.



thank you @myfrndjk


In my case The handiest choice left is iframe. I became thinking to stay in the node js aspect in preference to going to html aspect.
You would possibly say you can also proper NodeJS codes in html/javascript aspect but unfortunately now not, the link I’m looking to help with assignment writing load requires me to disable nodejs inside the window wherein i load the hyperlink.


setting up proxy only for webview using proxyrules

var proxyIp ='’
var port =‘8080’

<webview id="wv1" src="" partition="persist:webviewsession"></webview>

if(proxyIp.trim() =='noproxy'){
    var my_proxy = 'direct://';
    session.fromPartition('persist:webviewsession').setProxy({proxyRules:my_proxy}, function (){
        console.log('using the proxy  '  + proxyIp);

    var my_proxy = "http://"+proxyIp+":"+port;
    session.fromPartition('persist:webviewsession').setProxy({proxyRules:my_proxy}, function (){
        console.log('using the proxy  '  + proxyIp);


I want to use this program in my web development company website to make my website more user-friendly and easy to rank I have bee searching for so long time but I found very hard code that I don’t understand now it’s very useful thanks for sharing this idea with us.


In my case The handiest option left is border. I turn out to be thinking to stay in the swelling is feature in favorite to leaving to html feature. You would perhaps say you can as well proper Nodes codes in html/JavaScript characteristic but unluckily now not, the link I’m looking to Assignment Service UK load require me to put out of action nodes inside the casement wherein i weight the hyperlink.


thank you very much @myfrndjk


If you want to handle the content in any way, you can easily write JavaScript for web view events plus you can custom assignment help responds those events by using the web view techniques. These are the best techniques to manage the content in any way.


I am creating a web browser using Electron. My case is I want to route each URL via different/respective proxy-IPs. Professional Logo Designer
If the user types google uk it has to route via and if he types gmail it has to route via [Proxy/Port].I saw this somewhere on the web but it will not change proxy dynamically. Is it possible to do it in the electron?


Yes, It is possible. Check my first comment.You can use proxy.pac file if you already know all the websites users going to visit.


Not quite the same as the iframe, the webview keeps running amid a different technique than your application; it doesn’t have indistinguishable authorizations as your application and each one association between your application and inserted content are offbeat. This protects your application from the implanted substance. Case Study Assignment Writer


Hi all,
I want to re open this topic because i not found nothing in the forum and this topic have a similar question (indeed we also say the opposite).
I want to create a custom browser with electron, but for to navigate only in my intranet, then without navigate in the internet public site.

it is possible??



I have the same question i’m the webmaster of transplantation cheveux and i verry insterested to know howi can do proxy with wordpress ?


Hi, Am also facing similar issue to the site vidmate and I Hope to get a solution here.



I also agree with you, I have same issue with DroidsPC and as of yet I didn’t find any solution.