After a complaint from one of our users and running some tests it appears Firefox 15 and 16 (and probably older version) make it so if you disable cookies you also disable localStorage. You can't even create a polyfill for it as whenever you try to access window.localStorage you get Error: The operation is insecure.
Throwing a try catch will let you check to see if it's disabled but won't let you replace the variable with your own solution. The following quick polyfill will not work because FF ignores setting the variable and will throw the same error when trying to access it:
try{
window.localStorage;
}catch(err){
window.localStorage = {
getItem: function(k){
return this.k;
},
setItem: function(k,v){
this.k = v;
}
};
}
The only solution seems to be move the "fake" localStorage to another variable but this would be annoying as we have lots of code and a js lib that rely on accessing this variable. Any solutions?
Edit: It is not optimal to just pop up an alert to tell the users that cookies are required. If visitors just want to view the site and not signup then they truly don't need cookies. But being a backbone.js application and passing around a lot of data, we do store stuff in localStorage quite a bit.