Skip to content

localStorage doesn't persist on Linux + Windows #1731

Closed

Description

@anaisbetts

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

Activity

  1. hanzhao commented on May 20, 2015

    @hanzhao
    Contributor

    On ArchLinux, it's all right.

  2. CharlieHess commented on May 20, 2015

    @CharlieHess
    Contributor

    This is more severe; it's actually happening on all platforms.

  3. frankhale commented on May 20, 2015

    @frankhale
    Contributor

    @CharlieHess, by 'all platforms" do you mean all OSes Electron supports because I just tested Electron 0.26 x64 on Windows 10 preview and ran through the steps @paulcbetts mentioned and 'foo' is persisting for me.

  4. CharlieHess commented on May 20, 2015

    @CharlieHess
    Contributor

    @frankhale: Tested on Windows 8.1 and Yosemite. We're accessing localStorage from the renderer process (if that matters).

  5. changed the title [-]localStorage doesn't persist on Linux[/-] [+]localStorage doesn't persist on Linux + Windows[/+] on May 20, 2015
  6. frankhale commented on May 20, 2015

    @frankhale
    Contributor

    I assumed (most likely incorrectly) in @paulcbetts steps to reproduce that it was implied to open up Dev Tools and set / get 'foo' using the console.

  7. anaisbetts commented on May 20, 2015

    @anaisbetts
    ContributorAuthor

    @frankhale Yep, that's what I meant. However, now that I check Electron Win32 x64, it doesn't repro either. Maybe this has to do with how you exit Electron?

  8. zcbenz commented on May 21, 2015

    @zcbenz
    Contributor

    I haven't looked into it yet, but if the app crashes when quitting, or you use other ways like process.exit instead of app.quit to quit, the localStorage will not be persisted.

  9. CharlieHess commented on May 21, 2015

    @CharlieHess
    Contributor

    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. 😅

  10. nicozhang commented on Nov 6, 2015

    @nicozhang

    I meet the same problem with win10. When I am using an mapapi , it's js will judge whether the localstorage works, but the result is localstorage does not work. electron 0.34.2.

  11. bansalvks commented on May 26, 2016

    @bansalvks

    using electron 1.1.0 and lcoalStorage is not persisting. Any help is kindly appreciated. I am accessing local storage from browser window (rendered process)

  12. anaisbetts commented on May 26, 2016

    @anaisbetts
    ContributorAuthor

    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

  13. Lt0 commented on Oct 12, 2018

    @Lt0

    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.

  14. MutableLoss commented on Apr 8, 2019

    @MutableLoss

    I'm running into this with my Linux builds when using app.quit(), though the Windows and OSX builds have no issues persisting at all.

    Electron: 4.0.2

    Update: somehow the app's .config folder was owned by another user, blocking storage of the local storage.

  15. knaos commented on Nov 25, 2021

    @knaos

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

  16. anaisbetts commented on Nov 25, 2021

    @anaisbetts
    ContributorAuthor

    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 💃

  17. mcharytoniuk commented on Dec 7, 2021

    @mcharytoniuk

    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

  18. amoscatelli commented on Jan 22, 2022

    @amoscatelli

    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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions