How to get Electron cookies in Angular js


#1

Hello,

I am just creating an Electron app and I have created cookies in my main.js (node js). session.fromPartition('persist:sessionName').cookies
Using this i can set and get cookies data, I want to manage these cookies on Angular JS.

Please advice.


#2

You should be able to attach that data to a global variable in your main.js and access it with the remote package.

In main.js

global.cookies = whateverFunctionFetchesAndReturnsCookies();

And then in your angularApp.js

const remote = require('electron').remote;
const cookies = remote.getGlobal('cookies');


#3

Yes i create this way @riebschlager

var expiration = new Date();
var hour = expiration.getHours();
hour = hour + 12;
expiration.setHours(hour);
var Cook = {
“name”:“cookiename”,
“value”:“cookievalue”,
“url”: “http://localhosts/”,
“expirationDate”: expiration.getTime()
};
win.webContents.session.cookies.set(Cook,function(error) {
if (error) {
console.dir(error);
}
});

Is correct?