Vikas Bansal Vikas Bansal - 10 months ago 160
Node.js Question

ElectronJS: how to manipulate cookies from rendered Process(browser window)?

I am able to create persistent cookies from main process (app.js)


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

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

console.log(cookies); /// cookies values should be printed next time the applciation is launched.

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

if (error)

But when I am doing the same in Browser window, cookies are not being created and the
is undefined.

Please suggest what should I do to save persistent data in the browser.


Built-in modules that are not directly available in the renderer process (such as session) can be accessed via IPC, the remote module provides a simple way to do that (but you should be aware of its limitations). So you should be able to get your code working in the renderer process by simply changing the first line to:

const session = require('electron').remote.session;