Removing browser DOM storage add-on

Hi All,

I’m new to this forum, and would appreciate some help.
I’m having an issue in allowing my add-on to remove browser’s DOM storage. Currently it manipulates webappsstore.sqlite directly, but this approach leaves DOM storage in cache, requiring user to close an existing tab and reopen it again.

I figured there must be a better approach to this, so I tried the following:
var localStorage = domStorageManager.getLocalStorageForPrincipal(Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal), tab.url.uri);
localStorage.clear();

However this gives me an error: Message: [Exception… “Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMStorageM
anager.getLocalStorageForPrincipal]” nsresult: “0x80040111 (NS_ERROR_NOT_AVAILABLE)”

Is there anything I’m doing wrong here? Is there a better approach to managing DOM storage?

Thanks

session storage isn’t even in the sqlite file. Nor is any storage used in a private browsing window or when permissions are set to remove local storage at the end of the session.

Accessing local storage from an addon is a nightmare. Always has been, and its worse today than ever, partly because of multiprocess Firefox.

Looks like you’re doing this from the SDK? You may have to require something. Or it may not work at all. Double-check that the url is what you expect. Is tab.url.ral really what you want? In any case, getLocalStorageForPrincipal() is deprecated. You should use getStorage() now.

The “simple” way to access DOM storage is from the content process. It is automatically available as window.sessionStorage and window.localStorage. Messing with principals and XPCOM is very fragile and breaks every few releases. At the moment I don’t think you can get to session storage at all in multiprocess mode except from the content process (content script or frame script), and accessing local storage in the way you show will return the wrong storage area in some circumstances.