Peculiarity with Local Storage on Add-ons Manager Page


(Matthew G. Saroff) #1

I am using local storage to save user options in an extension that I am developing, so I want to access the contents of the storage to make sure that things are stored.

When I attempt to access the stored data using localStorage at the console prompt from the extension options page, I get an error:

[Exception... "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1"  data: no]

I get the same error when I attempt to write to localStorage with something like localStorage.setItem("lastname", "Smith");

I do not get an error from an ordinary web page, even when I access my options.html page directly, which makes it hard to see what is going on.

Is this a bug, or a feature, and is there a way to access local storage so that I can debug the options page?


(jscher2000) #2

Are you meaning to read/write WebExtensions storage (storage API) or the DOM storage for a particular website?


(Matthew G. Saroff) #3

Storage API, specifically storing things like turning on and off submenus and custom tags.


(jscher2000) #4

I think you need to use the syntax in this article – browser.storage.local.set():


(Matthew G. Saroff) #5

I just tried it, and browser.localStorage.setItem("lastname", "Smith"); gets me an ReferenceError: browser is not defined error.


(jscher2000) #6

I think the method is definitely available in background scripts. That opaque message sometimes indicate a required permission is missing.


(Matthew G. Saroff) #7

I have storage permissions in my manifest:

	"permissions": [
                "<all_urls>",
		"webRequest",
                "downloads",
                "notifications",
		"contextMenus",
                "menus",
		"storage",
		"tabs",
		"alarms",
		"activeTab",
                "clipboardRead",
                "clipboardWrite"
	],

(Matthew G. Saroff) #8

Interesting. I can access the local storage through the options.js, but not through the a statement typed in through the console.


(Martin Giger) #9

Ah, that sounds like you’re using the F12 console, which is in a different process.


(Matthew G. Saroff) #10

OK, which console should I use, and how do I access it?


(Martin Giger) #11

All the other sections of that page may also be of interest :slight_smile: