Embedded WebExt in overlay extension can't get storage

So, I’m trying to create an embedded WebExtension in order to migrate data from an overlay extension. Of course, it’s not as easy as it would be for the other types of legacy extensions, but I managed to find what I needed, and now the embedded webext is getting started, and messages can be sent. So, it’s… almost working.

For some reason, though, when I try to do a browser.storage.local.set(...), I get the error, “browser.storage is undefined”. It doesn’t matter whether the manifest.json includes the “storage” permission or not. Is setting permissions something the embedding code also has to take care of, or is there something else going on?

And yes, I made a reduced test by taking the published example and just adding browser.storage.local.set({foo: 42}); to it. Same result, with or without specifying the “storage” permission.

Hi,

I’m not sure why the storage API isn’t working for you. How are you invoking browser.storage? Could you push your non-working example test case to github?

I added a couple lines of storage setting and getting code to the example embedded overlay webextension, and it seems to be working for me. You can check out the code changes here.

Hope this helps,

Jared

Same thing with that code (fails when trying to write). I don’t need to push my example, as it’s the same without exception handling and debugging output.

I’m using an addondevel build, if that helps. Version 56.0b2. I downloaded it through the “Linux installer” link under “Beta builds” here. What about you?

Further info: I looked at the members of browser, and I see that while there are 41 of them, most are set to undefined. The ones that aren’t are events, types, tabs, windows, extensionTypes, extension, i18n, management, permissions, test, and runtime. Is that because of permissions?

A little more debugging, by checking permissions (browser.permissions.getAll(), etc.), shows that no permissions have been granted.

Hmm, that’s a pretty old build. 56 is currently in release, and a lot of patches landed after beta 2. Note that 57 will be in release on November 14th, so you still have some time to transition your users, but not a lot.

You can find more recent addon devel builds on treeherder, though the UI is maddeningly cryptic: https://treeherder.mozilla.org/#/jobs?repo=mozilla-release&filter-searchStr=addon%20build&selectedJob=134490896

From the list of builds on that page, you need to find one that has a little green (B) next to “Linux x64 addon opt” (if it’s a red B, the build is busted, ignore it). Click on the little green (B), then find the binary in the ‘Job Details’ tab that pops up at the bottom of the screen. So, in the case of linux, you’ll want to find “target.tar.bz2” (highlighted in this screenshot):

Here’s a direct link to a recent unbranded 56 release build for linux, in case you don’t want to navigate the maze of twisty passages: https://queue.taskcluster.net/v1/task/Bbq8cmROT0eKgWOOmAB-fQ/runs/0/artifacts/public/build/target.tar.bz2

I’d also suggest you try with a fresh profile, if you haven’t already.

Yeah, was already trying a new profile when you posted that. It works with that. Can’t see what’s wrong with the old profile. Probably some obscure preference or something. I hope that doesn’t end up being a problem for my users. Well, then, thanks for the help.

1 Like