I did my local storage using Chrome and then try to access it through Firefox. But it’s not there. Can somebody clarify that is it a valid test case to store and retrieve HTML5 local storage using different browsers? As per my understanding HTML local storage path is browser specific. So I assume that you need to use same browsers for both storage and retrieve belongs to a specific KEY. Is it a correct statement?
Local Storage is "local" in that exact browser and ONLY in that browser. To retrieve something stored in Local Storage, you must use the same browser, the same key and retrieve it from a page in the same origin (e.g. domain).
If you want something available across multiple browsers, then you would usually identify the user somehow (usually a user login) and then you would store the user's data on a server somewhere so that the data can be served to the same user across multiple browsers and even multiple computers/devices.
jfriend00 has correctly answered your question, however, I would like to caveat this by adding that there is a way to access your data on another browser even if its on another device, as long as this browser is Chrome. The way to do this is to use chrome.storage API, which has been available since Chrome 25.
The following are its benefits/features:
- User data can be automatically synced with Chrome sync (using storage.sync).
- Your extension's content scripts can directly access user data without the need for a background page.
- A user's extension settings can be persisted even when using split incognito behavior.
- It's asynchronous with bulk read and write operations, and therefore faster than the blocking and serial localStorage API.
- User data can be stored as objects (the localStorage API stores data in strings).
- Enterprise policies configured by the administrator for the extension can be read (using storage.managed with a schema).
© 2022 - 2024 — McMap. All rights reserved.