How to remove cookies in webview


#1

Since you can not get sessions when webview is not loading the target site or webview itself is not loaded.

And it looks like you can not delete them in main process because you can just remove BrowserWindow’s cookies in main process.


#2

check this out

http://electron.atom.io/docs/api/session/

cookies.remove(url, name, callback)


#3

Well, this way is used for main process and you should get a session.
That means you should load your webview first, but what can I do if not?
@wangxiexe


#4
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);
    });