Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

same localStorage for http and https?

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?

like image 870
user637980 Avatar asked Feb 28 '11 16:02

user637980


People also ask

Is local storage domain specific?

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 ).

Why is it better to use IndexedDB instead of localStorage?

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.

Is localStorage getItem synchronous?

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.

Is IndexedDB faster than localStorage?

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.


1 Answers

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;
    } 
});
like image 83
serg Avatar answered Oct 28 '22 20:10

serg