In Electron, how to use “login” event in webContents

Using “login” event of app is ok. But it fails when i try to use “login” event of webContents.

The following code is how I use “login” event of app, they are working fine.

// main.js
app.on('login', (event, webContents, request, authInfo, callback) => {

// render.js'login', (event, webContents, request, authInfo, callback) => {
      callback(username, password)

I tried this with webContents

      mainWindow.webContents.on('login', (event, request, authInfo, callback) => {
       console.log('webcontent login')
        callback(username, password)

The log “webcontent login” can be printed. But when the window shows in first time, it will wait a long time to load and always fail to connect.

Now I need to make every window to use a specific account and password of proxy.

“login” event of app doesn’t suit this situation, because it only emits once.

I assume “login” event of webContents suits the situation, but never get luck.

So how should i use it? Thanks in advance.

1 Like

I’m having this same issue. By any chance have you found the solution @cloudsthere?