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: /forum/#!topic/chromium-apps/_YcOT4PcdAQ
Chrome Management Settings
Added from ments: 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" style="width:100%; height:100%; position:absolute; top:0; left:0; right:0; bottom:0;"></webview>
</form>
</body>
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./a/chromium/forum/#!topic/chromium-apps/_YcOT4PcdAQ
Chrome Management Settings
Added from ments: 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." style="width:100%; height:100%; position:absolute; top:0; left:0; right:0; bottom:0;"></webview>
</form>
</body>
Share
Improve this question
edited May 23, 2017 at 11:54
CommunityBot
11 silver badge
asked Nov 25, 2015 at 20:16
JamesJames
1,3433 gold badges13 silver badges21 bronze badges
3
-
1
Post the code you've used for
chrome.storage
and the exact error text. – woxxom Commented Nov 25, 2015 at 20:29 - @wOxxOm chrome.storage.local.set({ 'key1': 'first', 'key2': 'second', 'key3': 'third', 'key4': 'fourth', 'key5': 'fifth' }, function() { console.debug('Settings saved'); }); error: TypeError: Cannot read property 'local' of undefined – James Commented Nov 25, 2015 at 23:48
- Could the issue be that the code is called from the Chrome App via a webview? CODE: <body class="trim full"> <foam id="kiosk" model="AppConfig" view="KioskView"> <webview id="browser" src="link-to-my-website-which-calls-localstorage." style="width:100%; height:100%; position:absolute; top:0; left:0; right:0; bottom:0;"></webview> </foam> </body> – James Commented Nov 25, 2015 at 23:53
1 Answer
Reset to default 9There are two contexts for localStorage
in a Chrome App.
The app's code itself.
localStorage
is disabled for Chrome App code. The only solution is to usechrome.storage
API.(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." 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).