0
votes

I'm have a strange issue in Firefox only.

I'm saving items to localStorage (one of which is a pretty large JSON object that I've stringified with JSON.stringify). The problem is that when I try to use removeItem() on the localStorage object it clears the entire thing. All the properties get cleared. But if I refresh the page the properties come back. This works in Safari, Chrome and Opera (latest versions) but only Firefox has this weird issue.

I've isolated the problem to a single line where I call localStorage.removeItem("value"). Has anyone seen anything like this before?

I've even done some debugging with the "storage" event on the window object, just to see what's happening. I included the output of that below. All this comes back when I try to delete one property, any property.

altKey undefined

attrChange undefined

attrName undefined

bubbles false

cancelable false

ctrlKey undefined

currentTarget Window weekend-getaways

data undefined

delegateTarget Window weekend-getaways

eventPhase 2

handleObj Object { type="storage", origType="storage", guid=9}

jQuery17207456704310204192 true

metaKey undefined

originalEvent storage

relatedNode undefined

relatedTarget undefined

shiftKey undefined

srcElement undefined

target Window weekend-getaways

timeStamp 1340773330422505

type "storage"

view undefined

which undefined

isDefaultPrevented returnFalse()

isImmediatePropagationStopped returnFalse()

isPropagationStopped returnFalse()

preventDefault function()

stopImmediatePropagation function()

stopPropagation function()

proto Object { preventDefault=function(), stopPropagation=function(), stopImmediatePropagation=function(), more...} storage changed cityli...0771360 (line 55)

altKey undefined

attrChange undefined

attrName undefined

bubbles false

cancelable false

ctrlKey undefined

currentTarget Window weekend-getaways

data undefined

delegateTarget Window weekend-getaways

eventPhase 2

handleObj Object { type="storage", origType="storage", guid=9}

jQuery17207456704310204192 true

metaKey undefined

originalEvent storage

relatedNode undefined

relatedTarget undefined

shiftKey undefined

srcElement undefined

target Window weekend-getaways

timeStamp 1340773330470620

type "storage"

view undefined

which undefined

isDefaultPrevented returnFalse()

isImmediatePropagationStopped returnFalse()

isPropagationStopped returnFalse()

preventDefault function()

stopImmediatePropagation function()

stopPropagation function()

proto Object { preventDefault=function(), stopPropagation=function(), stopImmediatePropagation=function(), more...} storage changed cityli...0771360 (line 55)

altKey undefined

attrChange undefined

attrName undefined

bubbles false

cancelable false

ctrlKey undefined

currentTarget Window weekend-getaways

data undefined

delegateTarget Window weekend-getaways

eventPhase 2

handleObj Object { type="storage", origType="storage", guid=9}

jQuery17207456704310204192 true

metaKey undefined

originalEvent storage

relatedNode undefined

relatedTarget undefined

shiftKey undefined

srcElement undefined

target Window weekend-getaways

timeStamp 1340773331099462

type "storage"

view undefined

which undefined

isDefaultPrevented returnFalse()

isImmediatePropagationStopped returnFalse()

isPropagationStopped returnFalse()

preventDefault function()

stopImmediatePropagation function()

stopPropagation function()

proto Object { preventDefault=function(), stopPropagation=function(), stopImmediatePropagation=function(), more...} storage changed cityli...0771360 (line 55)

altKey undefined

attrChange undefined

attrName undefined

bubbles false

cancelable false

ctrlKey undefined

currentTarget Window weekend-getaways

data undefined

delegateTarget Window weekend-getaways

eventPhase 2

handleObj Object { type="storage", origType="storage", guid=9}

jQuery17207456704310204192 true

metaKey undefined

originalEvent storage

relatedNode undefined

relatedTarget undefined

shiftKey undefined

srcElement undefined

target Window weekend-getaways

timeStamp 1340773332394871

type "storage"

view undefined

which undefined

isDefaultPrevented returnFalse()

isImmediatePropagationStopped returnFalse()

isPropagationStopped returnFalse()

preventDefault function()

stopImmediatePropagation function()

stopPropagation function()

proto Object { preventDefault=function(), stopPropagation=function(), stopImmediatePropagation=function(), more...} storage changed cityli...0771360 (line 55)

altKey undefined

attrChange undefined

attrName undefined

bubbles false

cancelable false

ctrlKey undefined

currentTarget Window weekend-getaways

data undefined

delegateTarget Window weekend-getaways

eventPhase 2

handleObj Object { type="storage", origType="storage", guid=9}

jQuery17207456704310204192 true

metaKey undefined

originalEvent storage

relatedNode undefined

relatedTarget undefined

shiftKey undefined

srcElement undefined

target Window weekend-getaways

timeStamp 1340773332395014

type "storage"

view undefined

which undefined

isDefaultPrevented returnFalse()

isImmediatePropagationStopped returnFalse()

isPropagationStopped returnFalse()

preventDefault function()

stopImmediatePropagation function()

stopPropagation function()

proto Object { preventDefault=function(), stopPropagation=function(), stopImmediatePropagation=function(), more...} storage changed cityli...0771360 (line 55)

altKey undefined

attrChange undefined

attrName undefined

bubbles false

cancelable false

ctrlKey undefined

currentTarget Window weekend-getaways

data undefined

delegateTarget Window weekend-getaways

eventPhase 2

handleObj Object { type="storage", origType="storage", guid=9}

jQuery17207456704310204192 true

metaKey undefined

originalEvent storage

relatedNode undefined

relatedTarget undefined

shiftKey undefined

srcElement undefined

target Window weekend-getaways

timeStamp 1340773361375308

type "storage"

view undefined

which undefined

isDefaultPrevented returnFalse()

isImmediatePropagationStopped returnFalse()

isPropagationStopped returnFalse()

preventDefault function()

stopImmediatePropagation function()

stopPropagation function()

proto Object { preventDefault=function(), stopPropagation=function(), stopImmediatePropagation=function(), more...} storage changed cityli...0771360 (line 55)

1
The biggest question that i saw ever in SOcoolguy
You can try using something like store.js or try checking out localStorage compatibility on Firefox: github.com/frankkohlhepp/store-jsWern Ancheta
next time try to make your questions shorter. A lot of details would definitely help but not this one. The details that you gave here is certainly not helpful. It actually prevents other people from answering your question.Wern Ancheta

1 Answers

0
votes

Sorry guys, I didn't even know how to explain this but I found the answer here: http://treasonx.com/blog/2012/05/08/firefox-localstorage-bug/

The bug shows up if you do the following. If your first interaction with localStorage is a removeItem you will not get the proper length from the localStorage object. It will seem as though all of the items in localStorage have been deleted. This is not the case, the browser just hasn’t updated its cache with the contents of localStoage.

This is the suggested workaround until the issue gets fixed:

The workaround for now is to get the length of the localStorage object before any other operation with localStorage so that it works as expected.