electron: localStorage doesn't persist on Linux + Windows

To repro:

  1. Open Electron on Ubuntu 14.04 32-bit (at least, prob. other places too)
  2. localStorage.setItem('foo', 'bar')
  3. Close the app
  4. Reopen the app
  5. localStorage.getItem('foo')
  6. >> undefined

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 18 (10 by maintainers)

Most upvoted comments

LocalStorage won’t persist if you kill the app via Ctrl-C or some other violent means, this is almost certainly the bug y’all are seeing

Even closing an application with “X” window button does not persist local storage, which seems to be the correct way to close an app. Electron needs a little help to prevent this. This is the helpful answer that resolved the issue for me: #5708 (comment)

Calling app.quit() manually in this event might be even more reliable: https://nodejs.org/api/process.html#event-beforeexit

Are using localestorage from main process or renderer process ?

Even when using process.on(‘exit’, () => app.quit());

my renderer process seems to lose data in localstorage when closing the application with “X”

So what if we want to prevent this behaviour? Is it still a bug.

If you want to prevent this behavior, exit your application correctly and it won’t happen 💃

I have the same issue on win10 when I reinstall my electron app. I just remove C:\Users\Lt0\AppData\Roaming\my-app-name to make it work.

So, it turns out that we were calling out to app.exit instead of app.quit. I can’t find any documentation on this method, but modifying all of our calls to use quit make localStorage persist as expected. I think we can close this one out. 😅