6

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?

user637980
  • 73
  • 2
  • 6
  • 1
    Are you trying to read localStorage created by the site? Or you just trying to store some extension settings there? Also why cookies is not an option? – serg Feb 28 '11 at 16:20
  • i'm trying to locally store (and keep track of) the time a user spends on a site that's not mine. i don't want to mess with the cookie of the site. i'm not that familiar with cookie use, so if you think that there's a possibility, go ahead :) – user637980 Feb 28 '11 at 16:24
  • See also [Is there any workaround to make use of html5 localstorage on both http and https?](http://stackoverflow.com/questions/10502469/is-there-any-workaround-to-make-use-of-html5-localstorage-on-both-http-and-https). –  Aug 13 '13 at 19:43

1 Answers1

5

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;
    } 
});
serg
  • 109,619
  • 77
  • 317
  • 330
  • interesting. at the moment, my javascript code is only initialized by a _content_scripts_ (meaning: only running when the site is active), so i suppose using the localStorage in this context means that the sites localStorage is used, not the extensions localStorage. any idea how to use the extensions storage? – user637980 Feb 28 '11 at 16:40