I'm developing a Chrome extension and I need to store some data and then get it in some point. I did investigation on available storage
s and came across to the following ones: window.localStorage
and chrome.storage.local
.
So my question is, which one is the right choice to use in Chrome extensions:
window.localStorage
or chrome.storage.local
?
P.S. I'm using browser action
to load a local HTML
in IFRAME
. So I'm not using popup.js
.
localStorage
Pros:
var value = localStorage[key]
Cons:
JSON.stringify
chrome.storage.local
Pros:
chrome.storage.onChanged
"unlimitedStorage"
permission, can hold arbitrarily large amounts of data.Has a nice built-in mechanism for default values:
chrome.storage.local.get({key: defaultValue}, function(value){/*...*/});
Cons:
Asynchronous, therefore a bit harder to work with:
chrome.storage.local.get("key", function(value){/* Continue here */});
chrome.storage.local.get(null)
to get all values or use something like Storage Area Explorer.chrome.storage.sync
Same as above, but:
Pros:
Cons:
As of 2016-11-06, not yet supported in either Firefox WebExtensions or Edge Extensions, so non-portable.
Note: storage.sync
is now FF WebExtension compatible, though there is no way to make Chrome and FF natively sync between each other.