How to retain cookies in node-webkit How to retain cookies in node-webkit node.js node.js

How to retain cookies in node-webkit


  1. You can get auth cookies using this instructions:https://github.com/nwjs/nw.js/wiki/window#windowcookies

  2. Save it with prefered method:https://github.com/nwjs/nw.js/wiki/Save-persistent-data-in-app

  3. On next start just check that record exists, and set cookies with method from 1.

Should be something like this:

var gui = require('nw.gui');var win = gui.Window.get();function login() {   var opts = {};   if(localStorage.auth) {      opts.cookies: [           'Auth': localStorage.auth      ];   }    someRequest.get(opts, function(result) {        if(result)          localStorage.auth = win.cookies.get('auth');    });}


As of 2018, NW.js retains cookies and other persistent browser data by default. These are stored in %LOCALAPPDATA%/name-in-manifest/ in Windows or equivalent depending on OS. Nothing is required from the application itself, you do not have to persist cookie data manually in local storage.