Chrome应用程序本地存储不持久,Chrome.storage不工作
Chrome App localStorage not persisting and chrome.storage not working
我有一个chrome Kiosk应用程序,我需要在机器打开和关闭之间保存数据(几个字节作为字符串)。但无论我怎么尝试,localStorage似乎在重新启动时就被擦除了。
当我去chrome://inspect/#apps要检查Chrome应用程序,控制台中没有与LocalStorage 相关的错误
在浏览器的Chrome中,我会简单地使用localStorage,但在Kiosk应用程序中这种情况不会持续存在。
代码示例:
window.localStorage.setItem(id, temp);
window.localStorage.getItem(id);
遵循此处的建议:跨单个应用程序kiosk模式执行持久化数据我有一个Chrome管理许可证,设置了以下设置,但这似乎没有任何区别(见附件JPG)
使用Kiosk应用程序,我在manifest.json 中拥有存储权限
我试过移动到chrome.storage,但当我尝试这样做时,我会遇到一个未定义的错误。当作为Chrome应用程序和浏览器运行时会发生此错误
我尝试过这里的解决方案,但都不起作用。总是得到一个未定义的错误:https://groups.google.com/a/chromium.org/forum/#!主题/铬应用程序/_YcOT4PcdAQ
Chrome管理设置
添加自注释:代码:
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>
Chrome应用程序中有两个localStorage
上下文。
-
应用程序的代码本身。对于Chrome应用程序代码,
localStorage
已禁用。唯一的解决方案是使用chrome.storage
API。 -
(您的案例)
<webview>
中的localStorage
。默认情况下,它被设计为临时。如果希望它持久化,则需要使用webview持久化分区。如果存储分区ID以
persist:
(partition="persist:googlepluswidgets"
)开头,则Web视图将使用可供应用程序中具有相同存储分区ID的所有来宾使用的持久存储分区。如果未设置ID或没有'persist:'
前缀,则Web View将使用内存中存储分区。<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>
请注意,
chrome.storage
API不会暴露于webview内容(除非注入脚本)。
- 模拟chrome.storage.local函数使用Jasmine
- chrome.storage.sync未定义错误
- chrome.storage.local.get 如何设置值
- chrome.storage.sync.get未返回值-Angular服务
- 同步同步和本地 chrome.storage
- chrome.storage.local["mykey"] is undefined
- Chrome扩展 chrome.storage 如何同时进行大量获取和设置并避免竞争条件
- 显示chrome.storage中的所有内容
- 使用chrome.storage.get获取变量
- 从chrome.storage.local获取基元值
- chrome.storage.local.set using a variable key name
- 如何使用chrome.storage扩展
- 将客户端生成的密码短语存储在chrome.storage.local中的安全含义
- Chrome.storage:它能持续多久
- Chrome.storage.sync 在重新加载扩展程序时会被覆盖
- 使用 chrome.storage.sync 保存/获取嵌套对象
- 在 chrome.storage 中正确存储对象
- chrome.storage.sync.set variable key
- 如果扩展程序的文件发生更改,请更新 chrome.storage
- 从“选项”弹出窗口中选择一个值,然后将其保存到 Chrome.storage,以便在后台脚本中用作值