i'm looking for a way to use the same localStorage (or similar) for both http:// example .com
and https:// example .com
according to this, that's not possible using localStorage. there doesn't seem to be a globalStorage
for chrome though.
i'm doing this for a chrome extension, so using cookies is not an option and compatibility with other browsers is not needed.
any ideas?
localStorage data is specific to the protocol of the document. In particular, for a site loaded over HTTP (e.g., http://example.com ), localStorage returns a different object than localStorage for the corresponding site loaded over HTTPS (e.g., https://example.com ).
localStorage is useful for storing smaller amounts of data, it is less useful for storing larger amounts of structured data. So if you want to store significant amounts of structured data then IndexedDB is what you should choose.
localStorage is a synchronous API. You could defer the setItem method execution with the Promise object, giving them an asynchronous behaviour: const asyncLocalStorage = { setItem: function (key, value) { return Promise.
LocalStorage is slightly faster than IndexedDB in all browsers (disregarding the crashes). IndexedDB is not significantly slower when run in a web worker, and never blocks the DOM that way.
If all you need is store time spent on the site in localStorage then you don't need to solve this http/https problem. Extensions have their own isolated localStorage that you can access anytime anywhere, so just store your data there.
You can access this localStorage only from a background page, so from a content script you will need to send a request to a background page first and then work with localStorage there:
content_script.js:
chrome.extension.sendRequest({do: "save", value: "some_value"});
background.html:
chrome.extension.onRequest.addListener(function(request) {
if(request.do == "save") {
localStorage["param"] = request.value;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With