Peculiarity with Local Storage on Add-ons Manager Page

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?

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

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

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

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

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

I have storage permissions in my manifest:

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

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

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

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

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