javascript - how not to lose data when closing and opening chrome extension popup - Stack Overflow

I'm new to chrome extension.I need to have data created when working with the popup, available af

I'm new to chrome extension. I need to have data created when working with the popup, available after closing and re-opening it.

Here're some more details about my specific problem:

whenever my chrome extension popup is opened a script runs. in the popup there's an option to click a button which will add an item to an array, which is used in order to display this list of items in another tab in this popup. However, since every time the popup is opened the code runs all over again, the array is emptied the moment the popup opens again, and obviously when the browser or the OS is restarted. I need this array to stay consistent through opening and closing of the OS, the browser and the popup itself. Any ideas?

btw - managing it from a background page is not good enough since the moment the os is restarted the background page session stops and the data is lost

I'm new to chrome extension. I need to have data created when working with the popup, available after closing and re-opening it.

Here're some more details about my specific problem:

whenever my chrome extension popup is opened a script runs. in the popup there's an option to click a button which will add an item to an array, which is used in order to display this list of items in another tab in this popup. However, since every time the popup is opened the code runs all over again, the array is emptied the moment the popup opens again, and obviously when the browser or the OS is restarted. I need this array to stay consistent through opening and closing of the OS, the browser and the popup itself. Any ideas?

btw - managing it from a background page is not good enough since the moment the os is restarted the background page session stops and the data is lost

Share asked Mar 29, 2015 at 22:41 AmnonAmnon 3254 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

When a popup is closed, its HTML document is pletely unloaded; you need to restore state when your popup loads every time it's opened. No way around that.

As you mention, it's possible to persist state information in the background page while the browser is running. But it's still temporary storage; you need to use persistent storage to save whatever state you need to save.

The most obvious (and remended) choice is chrome.storage API, specifically designed for this purpose. You can also use Web APIs such as localStorage or IndexedDB if you like.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744913917a4600717.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信