使用WebView元素在Electron应用程序中显示其他页面时,是否可以读取和写入其Cookie?
答案 0 :(得分:5)
是的,你可以:
const { session } = require('electron').remote
// Here we access the session via the partition name
// You could also get it from the webContents object
// (webContents.session)
const cookies = session.fromPartition(<yourWebviewPartionName>).cookies
// Get a specific Cookie
cookies.get(
{
url: <targetURL>,
name: <cookieName>
},
(error, result) => console.log('Found the following cookies', result)
)
// Get all cookies
cookies.get(
{},
(error, result) => console.log('Found the following cookies', result)
)
// Remove a cookie
cookies.remove(
<targetURL>,
<cookieName>,
error => {
if (error) throw error
console.log('cookie deleted')
}
)
document.cookies