简体   繁体   中英

LocalStorage variable not persisting in Chromium Kiosk mode

I have a web app that's been working fine using localStorage as a way to persist data. Just recently, maybe due to an update perhaps?, Chromium on Raspbian has decided that localStorage is not a thing it wants to do anymore. I don't really know how else to persist data. I only need to store the value of two variables. I am using the typical syntax of

localStorage.setItem(key, value)

When I power off the machine, the values are gone. I am using this on a live project and I'm in desperate need of a way to get this data to persist but I don't know how else to do it. SessionStorage doesn't persist through shut downs. Can anyone help? For reference, the chromium version is 65.0.3325.181

function grow(){
      currentZoom += 1;
      $("#content").css('font-size', currentZoom + 'px');
      $("#content").css('height', currentZoom + 'px');
      localStorage.setItem("storeSize", currentZoom);
      console.log("grow triggered");
  }


  function shrink(){
     currentZoom -= 1;
     $("#content").css('font-size', currentZoom + 'px');
     $("#content").css('height', currentZoom + 'px');
     localStorage.setItem("storeSize", currentZoom);
     console.log("shrink triggered");
  }

   function mirror(){
       $("testDisplay").addClass("mirror");
       localStorage.setItem("mirror", 1);
   }

What happens is that Chromium by default store profile and session data in the temp folder when launched in kiosk mode sometimes, I'm not sure why, this folder is purged on system reboot, at least on Raspbian, other OSes may behave differently. A comment suggested using cookies instead, but that won't work as they go in the temp folder as well.

You can pass a command line argument to Chromium in order to use a different location for profile data, that should solve the problem:

/usr/lib/chromium-browser/chromium-browser --kiosk --user-data-dir=/myprofilefolder/

Remember to make sure that the folder exists, and that the appropriate user has write permission.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM