How to remove cookies in webview


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.


check this out

cookies.remove(url, name, callback)


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?

let session = webview.getWebContents().session;
    session.cookies.get({ url : '' }, function(error, cookies) {
        let cookieStr = ''
        for (var i = 0; i < cookies.length; i++) {
            let info = cookies[i];
            cookieStr += `${}=${info.value};`;