Q:

How to stop Electron windows sharing cookies?

I am creating multiple browser windows in an electron app however I do not want them to share cookies. This is how I am currently creating the windows,
function createWindow() {
    // Create the browser window.
    let mainWindow = new BrowserWindow({ minWidth: 660, minHeight: 400, width: 1208, height: 680 })
    // setInterval(() => sendStatus(0, 'FAIL'), 5000);
    // Emitted when the window is closed.
    return mainWindow;
}

However when multiple windows are open they share cookies between them.

A:

You can define a session (or partition) for BrowserWindow instances
Browser windows in different sessions don't share cookies, so you just have to define different session for each of your windows. Like

let counter = 0

function createWindow() {
  let mainWindow = new BrowserWindow({
    webPreferences: {
      session: session.fromPartition(`${counter++}`)
    }
  })
  return mainWindow;
}

or any more sophisticated way.

