访问/写入Chrome应用localStorage [英] Accessing/writing to Chrome app localStorage

查看:334
本文介绍了访问/写入Chrome应用localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Chrome编写一个打包的应用程序。使用后台页面(而不是应用程序的主HTML页面)读取/写入localStorage值有什么好处?



目前,用户似乎以某种方式丢失数据我不能复制。现在,应用程序在主HTML页面的JavaScript中读写localStorage。这个问题可能与localStorage容器的上下文有关。问题可能出在localStorage容器的上下文中。当从后台脚本运行时,您将保存您的扩展的localStorage。从内容脚本运行时,您将保存到localStorage用于该特定网站。由google.com网页上的内容脚本编写的localStorage.setItem('xx','yyy')无法通过yahoo.com上内容脚本的localStore.getItem('xx')调用读取。


I'm writing a packaged app for Chrome. Is there an advantage to using the background page - instead of the app's main HTML page - to read/write the localStorage values?

Currently users seem to be losing data in ways I cannot duplicate. Right now the app reads and writes localStorage in the main HTML page's JavaScript. Would changing the app to use the background page's JavaScript fix this?

解决方案

The problem might be with the context of the localStorage container. When run from the background script you are saving the the localStorage of your extension. When run from a content script you are saving to a localStorage are for that specific website. localStorage.setItem( 'xx', 'yyy' ) that is written by a content script on a google.com page can't be read by localStore.getItem( 'xx' ) call from a content script on yahoo.com

这篇关于访问/写入Chrome应用localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆