Vikas Bansal Vikas Bansal - 5 months ago 27
AngularJS Question

ElectronJs with AnuglarJs: Cookies are not holding values if application is restarted

I am learning ElectronJs so I have started with making a simple AngularJs application with it and here I started stumbling.

I want to store some persistent data like user token and email id and so on. So, in order to do this, I am using


The given below example is working fine in (firefox, chrome) browser but when I am running the same example in electron browser window then it's storing the values temporarily and losing the values at the time of restart.

Please help, many thanks.


<!DOCTYPE html>
<html ng-app="myApp">

<script src=""></script>
<script src=""></script>
<meta charset="utf-8">
<title>AngularJS Cookies Example</title>

<body ng-controller="MyController">
{{platformCookie}} {{myFruit}} {{myFlower}}

<input type="button" value="setCookie" ng-click="setCookie()" />
<input type="button" value="getCookie" ng-click="getCookie()" />

var myApp = angular.module('myApp', ['ngCookies']);

myApp.controller('MyController', ['$scope', '$cookies', '$cookieStore',
function($scope, $cookies, $cookieStore) {
$cookies.userName = 'Vikas';

$scope.setCookie = function()
$scope.platformCookie = $cookies.userName;
$cookieStore.put('fruit', 'Apple');
$cookieStore.put('flower', 'Rose');

console.log('set cookies');

$scope.getCookie = function()
$scope.myFruit = $cookieStore.get('fruit');
$scope.myFlower = $cookieStore.get('flower');




Electron Session

I have also tried to use Electron Session in order to create persistent cookies, however, its also not working and getting disposed on the application restart.


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

// Query all cookies associated with a specific URL.
ses.cookies.get({ url: '' }, (error, cookies) => {

// Set a cookie with the given cookie data;
// may overwrite equivalent cookies if they exist.
const cookie = { url: '', name: 'dummy_name', value: 'dummy' };
ses.cookies.set(cookie, (error) => {
if (error)

using this code when you run the application second time it should display the cookies data that had been set but no luck.


Cookies are not persistent if you do not give them expirationDate

let cookie = {
            url: '',
            name: 'userDetailsGoogle',
            value: JSON.stringify(userDetailsGoogle),
            expirationDate: 2093792393999

If you give them expirationDate then cookies will persist