Open Bug 1192366 Opened 9 years ago Updated 2 years ago

event.storageArea === localStorage is sometimes false even when the event matches the storage area

Categories

(Core :: DOM: Core & HTML, defect)

38 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: mozilla, Unassigned)

References

Details

(Keywords: testcase)

Attachments

(1 file)

10.79 KB, application/x-xpinstall
Details
Attached file TorrentStatus.xpi
User Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0
Build ID: 20150514102509

Steps to reproduce:

1. Load attached xpi.
2. Open two tabs to http://www.quirksmode.org/html5/tests/storage.html, or a page of your choice that sets local storage items.
3. Set (or remove or clear) a local storage item in one tab.


Actual results:

1. The window being used to set the storage item shows an alert "It Matches".
2. The other tab shows an alert "It doesn't match".
Note that the alerts are modal and may appear in a different order.


Expected results:

Both alerts should indicate a match.  The same local storage area is being used by both pages.  They both show the set (or removed or cleared) storage item, but in one case the storage area shown on the event claims to be for a different area.

Description of the xpi: it is a stripped-down addon.  It creates a component that loads a frame script into every page.  The frame script observes dom-storage2-changed and reports whether each change is to a storage area matching content.localStorage.  It is not signed!  I am raising this from branch 38, but have also tested in branch 42 nightly in e10s mode.
Blocks: 1043106
I'm confused. In the subject you say 'event.storageArea', while in the code the only thing I see is this (in your frame script):

  9 var observer =
 10 {
 11     QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver]),
 12     observe: function(aSubject, aTopic, aData)
 13     {
 14         // report whether this even matches our local storage area
 15         content.alert(aSubject.storageArea === content.localStorage ? "It matches" : "It doesn't match");
 16     }
 17 }
 18
 19 Services.obs.addObserver(observer, "dom-storage2-changed", false);

Even though the same storage area is used in two tabs, the *Storage objects in different tabs have different identities.

bug 1043106's usecase was to distinguish various types of storages (session/local) in a 'storage' event on a web page. I believe the storage2 notification provides this (bug 970383).

What's your usecase? Perhaps it has a different solution.
Component: Untriaged → DOM
Keywords: testcase
Product: Firefox → Core
Thanks for showing me that.  I wasn't previously aware of the type indication from dom-storage2-content notifications.

However this bug is about detecting whether the modified storage area is of interest to this page.  The notification is sent to every observer regardless of origin, hence it is useful for a page (frame script in my case) to be able to check whether it is the storage area for that page.  Storage event *nearly* does this, but it is not sent to the page which made the change (I know, dumb spec).

aSubject is a storage event, so aSubject.storageArea is event.storageArea.  For the page that made the change, it is strictly equal to content.localStorage (or sessionStorage).  For other pages with the same origin, and hence associated with the same local storage area, it is not equal.  Hence there is no way to know if the change affected the DOM storage for the current document.  I thought that bug 1043106 had fixed this, but not quite.
I can actually achieve what I need using both the storage and MozStorageChanged (didn't exist when the my addon was first written) events.  The matching works for those, but not for the dom-storage2-changed notification.
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: