When using a WebView element for displaying other pages inside an Electron app, is it possible to read and write its cookies?
Yes you can:
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
via contentscripts (preload scripts)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With