Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElectronJS: how to clear all cookies from a session?

Tags:

electron

I am creating cookies using the code given below:

///Cookie
let cookie = {
    url: 'http://www.example.com',
    name: 'oauthDetailsGoogle',
    value: JSON.stringify(oauthDetailsGoogle),
    expirationDate: oauthDetailsGoogle.accessTokenExpireDateTime
};

///save cookie
electronConstants().mySession.cookies.set(cookie, (error) => {

    ///if error then return error
    if (error) {
        defer.reject(error);
    }
    ///return null if no error
    else {
        defer.resolve(true);
    }
});

In order to delete cookies I am using the following code:

electronConstants().mySession.cookies.remove('http://www.example.com', 'oauthDetailsGoogle', function (data) {
            console.log(data);
        });

Suppose I have created 10 cookes so in order to delete 10 cookes I will have to call the remove function 10 time with the specific details?

Please guide.. Many thanks

like image 962
Vikas Bansal Avatar asked May 30 '16 07:05

Vikas Bansal


1 Answers

Finally, I found a solution in Electron Documentation : Source

here is the function that clear everything in one go:

electronConstants().mySession.clearStorageData([], function (data) {
    console.log(data);
})

The first parameter takes options so you can customize what you want to clear. Refer the documentation link that I provided above.

Many thanks.

like image 92
Vikas Bansal Avatar answered Nov 05 '22 13:11

Vikas Bansal