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();
});