Reputation: 163
I am not able to clear the cookies of a website in Webview.
I tried to clear storage using -
let session=require('electron');
session.clearCache(function () {
// console.log("cache clear");
});
session.clearStorageData();
session.defaultSession.cookies.get({}, (error, cookies) => {
cookies.forEach((cookie) => {
let url = '';
// get prefix, like https://www.
url += cookie.secure ? 'https://' : 'http://';
url += cookie.domain.charAt(0) === '.' ? 'www' : '';
// append domain and path
url += cookie.domain;
url += cookie.path;
session.defaultSession.cookies.remove(url, cookie.name, (error) => {
if (error) console.log(`error removing cookie ${cookie.name}`, error);
});
});
});
Then I tried to clear cookies of webview by accessing getWebContents()
but 'getWebContents()' is not available on console when I tried. How to access the webview and then clear session so that next user can't login with the last user's creds?
Upvotes: 1
Views: 1890
Reputation: 278
Try this see source
electronConstants().mySession.clearStorageData([], function (data) {
console.log(data);
})
Upvotes: 2