What is better to use Google Сhrome Extention extensions for storing data, and what is the fundamental difference between
localStorage , taking into account the possibility of obtaining this data in any tab?
Preferably with an example, please.
localStorage is HTML5 data storage. Documentation https://developer.mozilla.org/en/docs/Web/API/Window/localStorage
localStorage stores data in the form: name = value (value is a string), that is, it does not allow storing compound objects. Moreover, types like
false will be stored as
"false" . Data are accessed using a synchronous method:
var x = localStorage.x; var x = localStorage['x']; var x = localStorage.getItem('x');
chrome.storage.local – extension data storage. Allows to store objects, unlike
localStorage . Data is accessed asynchronously. Allows you to "listen" to changes in variables. Storage documentation https://developer.chrome.com/extensions/storage
chrome.storage.sync – works like
chrome.storage.local , but stores data on the server, synchronized by google account between all authorized browsers.
For extensions, it is preferable to use
sync – depends on your needs