简体   繁体   English

chrome扩展程序中的localStorage-扩展程序还是页面存储?

[英]localStorage in chrome extensions - Extension or page storage?

If I use localStorage in a Google Chrome extension, is it the storage of the current webpage, or is it the storage of the extension? 如果我在Google Chrome扩展程序中使用localStorage ,是存储当前网页还是扩展程序?

Alternatively, how can I reach each localStorage independently? 另外,如何才能独立访问每个localStorage

Depends on where you use it. 取决于您在哪里使用它。 If you use it on the background or options page, it is of the extension, and it is shared. 如果在backgroundoptions页面上使用它,则它是扩展名,并且是共享的。 If it is from a content script, it is on the specific page. 如果来自内容脚本,则它位于特定页面上。 You can't reach the localStorage of each page at will, so if you want to do that, you should send a request to the background and store it in the extension's storage. 您无法随意访问每个页面的localStorage ,因此,如果要执行此操作,则应将请求发送到后台,并将其存储在扩展程序的存储中。

Note that if you're using the extension's storage, you may want to use chrome.storage instead. 请注意,如果您使用扩展程序的存储空间,则可能要改用chrome.storage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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