Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome App localStorage not persisting and chrome.storage not working

I have a chrome Kiosk App which I need to save data (a few bytes as a string) between the machine turning on and off. But what ever I try, the localStorage seems to be wiped on restart.

When I go to chrome://inspect/#apps to inspect the Chrome App, there are no related errors in the console regarding to LocalStorage

Within Chrome in a browser, I would simply use localStorage but this does not persist when in a Kiosk App.

Example of code:

window.localStorage.setItem(id, temp);
window.localStorage.getItem(id);

Following the advice here: Persist data across single app kiosk mode executions I have a Chrome Management Licence with the following settings set but this does not seem to have made any difference (see attached JPG)

With the Kiosk App, I have the storage permission in the manifest.json

I have tried moving to chrome.storage but I get an undefined error when ever I try and do this.This error occurs when running as a Chrome App and in the browser

I have tried the solutions here but they don't work. Always get an undefined error: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-apps/_YcOT4PcdAQ

Chrome Management Settings


Added from comments: CODE:

chrome.storage.local.set({ 'key1': 'first', 'key2': 'second', 'key3': 'third', 'key4': 'fourth', 'key5': 'fifth' }, function() { console.debug('Settings saved'); });

<body class="trim full">
  <form id="kiosk" model="AppConfig" view="KioskView">
    <webview id="browser" src="link-to-my-website-which-calls-localstorage.com" style="width:100%; height:100%; position:absolute; top:0; left:0; right:0; bottom:0;"></webview>
  </form>
</body>
like image 583
James Avatar asked Nov 25 '15 20:11

James


People also ask

Does Chrome sync local storage?

sync , the stored data will automatically be synced to any Chrome browser that the user is logged into, provided the user has sync enabled. When Chrome is offline, Chrome stores the data locally. The next time the browser is online, Chrome syncs the data. Even if a user disables syncing, storage.

Can Chrome extensions use localStorage?

You can call localStorage directly from the options page or use chrome. extension.


Video Answer


1 Answers

There are two contexts for localStorage in a Chrome App.

  1. The app's code itself. localStorage is disabled for Chrome App code. The only solution is to use chrome.storage API.

  2. (Your case) localStorage inside a <webview>. It's designed to be temporary by default. If you wish for it to persist, you need to use a webview persistent partition.

    If the storage partition ID starts with persist: (partition="persist:googlepluswidgets"), the webview will use a persistent storage partition available to all guests in the app with the same storage partition ID. If the ID is unset or if there is no 'persist:' prefix, the webview will use an in-memory storage partition.

    <webview id="browser"
             src="link-to-my-website-which-calls-localstorage.com"
             style="width:100%; height:100%; position:absolute; top:0; left:0; right:0; bottom:0;"
             partition="persist:browser">
    </webview>
    

    Do note that chrome.storage API will not be exposed to webview content (unless you inject a script).

like image 122
Xan Avatar answered Oct 14 '22 12:10

Xan