How connect to proxy in electron webview?

#1

Hello for all

as I can connect through a to a free proxy server (or pay), currently in use as electron JS solution as desktop application

i am triying create a broswer

I’ve seen a library of protocol but not how to use it and how to dynamically change the protocol ( ip if not available )

PROTOCOL DOC => electron/electron/blob/master/docs/api/protocol.md

I need to connect to this timely

#2

Hi change your main.js like below code.
remove the comments in code if you wants to change that dynamically.
When ever you change proxy.pac file it will automatically reloaded.

  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, 60000);
//function myTimer() {
   //mainWindow.webContents.session.setProxy({pacScript:'file://' + __dirname + '/fun.pac'}, function () {return true;});
//}

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

  mainWindow.openDevTools();
});
#3

Hi jeyakumar
I am confuse in set proxy for my electron app.
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
height: 8100,
useContentSize: true,
width: 1500,
})

// and load the index.html of the app.
const isOnline = require(‘is-online’);

(async () => {
console.log(await isOnline());
const ISOnline = await isOnline();
if (ISOnline) {
mainWindow.loadURL(‘http://xyz.com’);
} else {
mainWindow.loadFile(‘index.html’);
}
//=> true
})();

Please help me to set proxy.
My Proxy setting is as follows:
192.xx.xx.xxx:8080
Username:xyzuname
Password: xyzpass