Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension Saving Data

I am working on a Chrome extension that needs to save some information (tabs info mainly) that will exist throughout the lifetime of the extension (e.g , since the user starts using it until he closes the browser).

One option is to use localstorage, however localstorage can only save Strings and that makes it very uncomfortable for me (since I have a bunch of data to save - dates , URLs , integers etc). What I'm looking for is using my own javascript objects that will live throughout the time of the extension.
Now the problem is that defining these objects in a script in some javascript files will erase them each time the user clicks on the browser action . In other words I have a browser action called popup.html that includes a javascript file (in which I want to save my objects) and every time the user clicks on the browser action all the objects I defined in the JS file are lost, yet I want everything to be persisted .

What option do I have to keep data that persists through many clicks on the browser action and that is NOT localstorage?

like image 376
Joel Blum Avatar asked May 28 '12 15:05

Joel Blum


3 Answers

You really should use localStorage (you may use JSON.stringify and JSON.parse).

If you really don't want to use localStorage nor a server side storage, use IndexedDb : https://developer.mozilla.org/en/IndexedDB/Using_IndexedDB

like image 101
Denys Séguret Avatar answered Oct 01 '22 21:10

Denys Séguret


Try using the Filesystem API's persistent storage. That is more reliable than localStorage. localStorage will be cleared once the user clears the cache, cookies etc. Filesystem is more reliable.

like image 20
Jophin Joseph Avatar answered Oct 01 '22 20:10

Jophin Joseph


This answer about using chrome.storage worked for me far better than the others.

https://stackoverflow.com/a/14009240/766115

It's like localStorage, but works between the popup / background and content scripts.

like image 21
Jesse Smith Avatar answered Oct 01 '22 20:10

Jesse Smith