How to read cookies from electron webview?


#1

Happy new year!

I have a trouble… In an Electron app, I used webView element to display an website and I want read cookies of the webView.

Is it possible?


#2

it is possible. :smiley:


#3
let session = webview.getWebContents().session;
session.cookies.get({ url : 'http://www.google.com' }, function(error, cookies) {
    console.log(cookies);
    let cookieStr = ''
    for (var i = 0; i < cookies.length; i++) {
        let info = cookies[i];
        cookieStr += `${info.name}=${info.value};`;
        console.log(info.value, info.name);
    }
    console.log(cookieStr);
});