Browser.storage.sync/local.get/set not working

I am building a simple extension that needs to save some basic data. However, the browser.storage is not working at all. Here is my code:

browser.storage.local.set({kitten: { name: “Mog”, eats: “mice” }})
.then(() => {
browser.storage.local.get([“kitten”])
.then(results => console.log(results))
}).catch(e => console.error(e))

It just prints this:

Am I using the functions wrong? How exactly can I save this data locally which can be used later?

Seems fine to me:
image

Where are you testing this?

I am testing for the console logs in the Browser Toolbox. Also, ‘browser’ is not defined when I try running it in the Browser Toolbox too.

I just checked in the Developers Toolbox Storage. It seems that the items are getting stored after all. But for some reason, I can’t seem to access it.


What are the reasons this is not working for me? I have added the addon ID too: “gecko”: {
“id”: “{ec8030f7-c20a-464f-9b0e-13a3a9e97384}”,
“strict_min_version”: “42.0”
}

Thanks.
I solved the issue. It seems that the value was getting saved always.
I just couldn’t see the items getting saved in the seperate Browser Toolbox window where I was trying to console.log() the item. Why? I still don’t know.
But then I clicked on ‘Inspect’ for my extension in the “about:debugging” page, and there, I ran the following code just as you did. It worked, and I could also see the keys and values under Storage.
This is probably a glitch in the Browser Toolbox Window, and anyone facing this problem should try debugging like @freaktechnik

Thanks for the help!

The normal browser toolbox runs in a browser context, not an extension context. That’s why it worked fine when you used the debugger for the extension.