How to set proxy for each webview tag in electronjs


#1

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!


#2

Hi,

If you want to set proxy for different web view check this https://github.com/electron/electron/issues/8247#issuecomment-268435712 [I didn’t tested this]

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

Main.js

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

  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');});
  mainWindow.openDevTools();
});

Proxy.pac

function FindProxyForURL(url, host) {

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

   if (shExpMatch(url, "*amazon*"))
         return "PROXY 194.73.29.74:8080";
    
   return "DIRECT";
 
}

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


#3

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="https://github.com" partition="persist:github"></webview> <webview id="wv2" src="http://electron.atom.io" partition="electron"></webview>


#4

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

Thanks for this link @myfrndjk.


#5

@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.

Thanks


#6

thank you @myfrndjk


#7

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.


#8

setting up proxy only for webview using proxyrules

var proxyIp ='12.12.133.12’
var port =‘8080’

<webview id="wv1" src="https://github.com" 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);
    });

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

#9

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.


#10

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.


#11

thank you very much @myfrndjk


#12

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.


#14

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 123.123.122.1:8081 and if he types gmail it has to route via 111.111.111.123:8080 [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?


#15

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.


#19

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


#22

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??

Thanks