Electron cookie

后端 未结 1 557
逝去的感伤
逝去的感伤 2021-01-21 11:03

For electron cookie I used https://www.npmjs.com/package/electron-cookies

Then added this into my html



        
相关标签:
1条回答
  • 2021-01-21 11:24

    This is how electron handles his own cookies.

    var session = require('electron').remote.session;
    var ses = session.fromPartition('persist:name');
    

    This is how to set a cookie

         function setCookie(data, name) {
            var expiration = new Date();
            var hour = expiration.getHours();
            hour = hour + 6;
            expiration.setHours(hour);
            ses.cookies.set({
                url: BaseURL, //the url of the cookie.
                name: name, // a name to identify it.
                value: data, // the value that you want to save
                expirationDate: expiration.getTime()
            }, function(error) {
                /*console.log(error);*/
            });
        }
    

    This is how to get the value of the cookie

        function getCookie(name) {
            var value = {
                name: name // the request must have this format to search the cookie.
            };
            ses.cookies.get(value, function(error, cookies) {
                console.console.log(cookies[0].value); // the value saved on the cookie
            });
        }
    

    For more information about the cookies of electron you can read here

    0 讨论(0)
提交回复
热议问题