简体   繁体   中英

localStorage in Firefox extension throws “The operation is insecure.” exception

I am developong Firefox Add-on that uses localStorage to store user data in website context. It access localStorage via injected content scripts using standard methods:

localStorage.getItem(key);
localStorage.setItem(key, value);

The code that calls localStorege is injected to website via PageMod:

pageMod.PageMod({
    contentScriptFile: [
        self.data.url("app.js")
    ]})

When methods getItem/setItem are called, security exception is thrown:

[Exception... "The operation is insecure." code: "18" nsresult: "0x80530012 (SecurityError)" location: ""]

So far I did not find out the reason why this is happening. I have an suspicion that it may have something to do with old FireFox bug, but probability is low: http://meyerweb.com/eric/thoughts/2012/04/25/firefox-failing-localstorage/

Maybe anyone could suggest an idea what could cause a problem?

Additional info:

  • We are using Addon SDK 1.16
  • Problem occurs since FF 29.0 RC1 (everything works with FF 28)

We also have an extension and are getting the same error with local storage. This is a bug with 29, as @basarat notes this error should only be thrown for CORS issues. We've tested with Aurora and Nightly with no issues either. We're filing a bug with Mozilla.

As previously noted, this is a bug in Firefox 29 and should be resolved in version 30: https://bugzilla.mozilla.org/show_bug.cgi?id=980023

For the time being, you can work around this issue by reassigning the localStorage object used in your content script:

var localStorage = unsafeWindow.localStorage;

The operation is insecure. should only be thrown when you load a JavaScript file cross domain. To enable is operation as secure the domain serving the JS file must enable CORS : http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM