Last Comment Bug 662511 - localStorage.key() gets out-of-sync when localStorage is updated in a separate window
: localStorage.key() gets out-of-sync when localStorage is updated in a separat...
Status: RESOLVED FIXED
[inbound]
:
Product: Core
Classification: Components
Component: DOM (show other bugs)
: unspecified
: x86 Mac OS X
: -- normal (vote)
: mozilla8
Assigned To: Honza Bambas (:mayhemer)
:
Mentors:
http://dev-test.nemikor.com/bugs/fire...
Depends on: 683316
Blocks:
  Show dependency treegraph
 
Reported: 2011-06-07 06:39 PDT by Scott González
Modified: 2012-01-05 16:03 PST (History)
5 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
test, v1 (1.35 KB, patch)
2011-06-09 14:28 PDT, Honza Bambas (:mayhemer)
no flags Details | Diff | Splinter Review
v1 (4.73 KB, patch)
2011-06-09 14:34 PDT, Honza Bambas (:mayhemer)
jst: review+
Details | Diff | Splinter Review

Description Scott González 2011-06-07 06:39:39 PDT
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.
Comment 1 Honza Bambas (:mayhemer) 2011-06-09 13:57:42 PDT
I'll write a test for this to confirm.
Comment 2 Honza Bambas (:mayhemer) 2011-06-09 14:28:30 PDT
Created attachment 538354 [details] [diff] [review]
test, v1

Confirming with this failing test.
Comment 3 Honza Bambas (:mayhemer) 2011-06-09 14:34:25 PDT
Created attachment 538356 [details] [diff] [review]
v1
Comment 4 Honza Bambas (:mayhemer) 2011-08-03 14:43:59 PDT
http://hg.mozilla.org/integration/mozilla-inbound/rev/088a2d2cdf33
Comment 5 Marco Bonardo [::mak] 2011-08-04 03:17:47 PDT
http://hg.mozilla.org/mozilla-central/rev/088a2d2cdf33
Comment 6 Honza Bambas (:mayhemer) 2011-09-23 09:16:31 PDT
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 Ian Nartowicz 2011-12-18 09:51:18 PST
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 Colin Blake 2012-01-04 18:40:45 PST
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 Colin Blake 2012-01-04 19:49:08 PST
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 Colin Blake 2012-01-05 08:45:20 PST
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 Colin Blake 2012-01-05 16:03:49 PST
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.

Note You need to log in before you can comment on or make changes to this bug.