The default bug view has changed. See this FAQ.

localStorage.key() gets out-of-sync when localStorage is updated in a separate window

RESOLVED FIXED in mozilla8

Status

()

Core
DOM
RESOLVED FIXED
6 years ago
5 years ago

People

(Reporter: Scott González, Assigned: mayhemer)

Tracking

unspecified
mozilla8
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [inbound], URL)

Attachments

(1 attachment, 1 obsolete attachment)

(Reporter)

Description

6 years ago
User-Agent:       Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.10 Safari/535.1
Build Identifier: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1

If there are two windows open with pages on the same domain, localStorage.keys() won't include data written from the other page.

Reproducible: Always

Steps to Reproduce:
1. Open a window and call localStorage.clear()
2. Open another window and call localStorage.setItem( "a", "a" )
3. Go back to the first page and call localStorage.key( 0 );

Actual Results:  
An error is thrown because the index is out of range.

Expected Results:  
The key "a" should be returned.

Accessing localStorage.length causes the keys to update.
Component: General → DOM
Product: Firefox → Core
QA Contact: general → general
(Assignee)

Comment 1

6 years ago
I'll write a test for this to confirm.
Assignee: nobody → honzab.moz
(Assignee)

Comment 2

6 years ago
Created attachment 538354 [details] [diff] [review]
test, v1

Confirming with this failing test.
(Assignee)

Updated

6 years ago
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
(Assignee)

Comment 3

6 years ago
Created attachment 538356 [details] [diff] [review]
v1
Attachment #538356 - Flags: review?(jst)
(Assignee)

Updated

6 years ago
Attachment #538354 - Attachment is obsolete: true

Updated

6 years ago
Attachment #538356 - Flags: review?(jst) → review+
(Assignee)

Comment 4

6 years ago
http://hg.mozilla.org/integration/mozilla-inbound/rev/088a2d2cdf33
Whiteboard: [inbound]
http://hg.mozilla.org/mozilla-central/rev/088a2d2cdf33
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla8
(Assignee)

Updated

6 years ago
Depends on: 683316
(Assignee)

Comment 6

6 years ago
The patch for this bug has been backed out from Aurora by https://hg.mozilla.org/releases/mozilla-aurora/rev/de96bbe87419 because of bug 683316.  Fix for this bug and for bug 683316 too has been landed on mozilla-central.  It will be merged to Aurora in some 5 days.

Comment 7

5 years ago
I'm still saying this same basic behaviour in 11.0a1.  Has this landed yet?

What I see is:
1. Open two different windows at http://trippingthebits.com/webstorage/test.html
2. Enter a local storage item in the 1st window.
3. Press dump button in the 1st window, item is shown.
3. Press dump button in the 2nd window, nothing.
4. Enter an item in the second window.
5. Press button in 2nd window, both items are shown.

Comment 8

5 years ago
I'm seeing something similar in Firefox 9.0.1.

Turn on Private Mode and then create two tabs both in http://trippingthebits.com/webstorage/test.html

Perform the following in the "local" section of the test page:

In tab 1 save test1/1 and then dump. Test1 can be seen.
In tab 2 hit dump. test1 is missing.

In tab 2 save test2/2 and then dump. Test2 is seen, but test1 is still missing.
In tab 1 hit dump. Test2 can be seen but test1 has gone!!

In tab 1 save test3/3 and hit dump. Now all three are seen.
In tab 2 hit dump. Only test 3 is seen.

Slightly different, but still incorrect, behavior is seen with non-Private Mode.

Comment 9

5 years ago
This is a similar test in non-Private mode. Create two tabs, enable Firebug in those tabs, and then load the test page in both tabs.

In tab 1 save test1/1 and then dump. Test1 can be seen.
In tab 2, hit dump. Nothing is displayed.

At Firebug command line prompt, enter localStorage.length. It's 1 !!!
At Firebug command line prompt, enter localStorage.key(0). It shows test1
Hit DUMP again, still nothing.

Why can Firebug commands see the contents of the localStorage but the JS code on the page can't?

Comment 10

5 years ago
Please ignore comment #8 and comment #9. While the problems I describe do occur when using the test page http://trippingthebits.com/webstorage/test.html, that page is not using localStorage directly (it's using a jQuery webStorage plugin). If I try the same tests on similar page which uses localStorage directly then everything behaves as expected.

Comment 11

5 years ago
Bug 715700 describes what appears to be a similar bug. However with 715700 the problem can only be seen in Private Mode and appears to have been introduced in Firefox 9.
You need to log in before you can comment on or make changes to this bug.