如何停止Electron Windows共享cookie? [英] How to stop Electron windows sharing cookies?
本文介绍了如何停止Electron Windows共享cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在电子应用程序中创建多个浏览器窗口,但是我不希望它们共享Cookie。这是我当前创建窗口的方式,
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;
}
但是,当打开多个窗口时,它们之间会共享cookie。
However when multiple windows are open they share cookies between them.
推荐答案
您可以定义会话
(或分区
)用于 BrowserWindow
实例
You can define a session
(or partition
) for BrowserWindow
instances
不同会话中的浏览器窗口不共享cookie,因此您只需要为每个窗口定义不同的会话。像
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;
}
或任何更复杂的方式。
这篇关于如何停止Electron Windows共享cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文