1

I have an electron app that will sometimes be used behind corporate firewalls.

I have added a login event listener to the app and requesting username and password from the user via a dialog box.
It's working fine if the user enters their details correctly the first time, but if there is an error with the first attempt and then the user enters the correct details the second time, the request seems to stall and then timeout. If I activate another HTTP request, creating a third auth request, and enter the details correctly, it works.

Here is the code from the main process in it's current form:

const requestHistory = [];

let onAuthCallback = function (username, password) {
  const lastIndex = requestHistory.length - 1;
  if (lastIndex < 0) {
    return;
  }

  const {callback} = requestHistory[lastIndex];
  callback(username, password);
};

app.on('login', (event, webContents, request, authInfo, callback) => {
  event.preventDefault();
  mainWindow.webContents.send('proxy-auth:req', authInfo);
  requestHistory.push({event, webContents, request, authInfo, callback});
});

ipcMain.on('proxy-auth:userpass', (event, userpass) => {
  console.info('userpass:', userpass);
  const {username, password} = userpass;
  try {
    console.info('proxy-auth with "%s" "%s"', username, password);
    onAuthCallback(username, password);
  } catch (error) {
    console.error('ERROR in `proxy-auth:userpass`:', error);
  }
});

If anyone has any pointers that would be great. At the moment I'm thinking of just ignoring any second request to get this out quickly.

Thanks

Qazzian
  • 684
  • 6
  • 9

1 Answers1

0

So the answer is that there is currently a bug in Electron

https://github.com/electron/electron/issues/16010

That bug report has some suggestions to work around the problem.

Qazzian
  • 684
  • 6
  • 9