Requesting permissions in a devtools panel (Manifest V3)

I work on a developer tools extension (https://addons.mozilla.org/en-US/firefox/addon/odd-devtools/) that requires host permissions to allow it to inject a content script used for communicating between a page and the extension.

I would like to prompt the user for host permissions at install time, but I can see from other posts (for example How to ask user to grant permissions for 'Access your data for all websites' through a prompt during the installation process) that this is not currently possible.

As an alternative, I have been attempting to request the permissions at runtime as recommended in https://blog.mozilla.org/addons/2022/11/17/unified-extensions-button-and-how-to-handle-permissions-in-manifest-v3/.

When I attempt to use the permissions API in a devtools or panel script, browser.permissions is undefined. Is there a way to request permissions from these contexts? My extension also uses a background script and content scripts, but no user facing UI outside of the devtools panel.

Yeah, you may need to create a separate html page just to ask permissions…

This could be part of the onboarding process - after the addon is installed, you open new tab that explains what permissions are needed and a big button to request them.

And then later if your code fails because of the lack of permissions you simply reopen this “onboarding” page in a new tab (or modal window).

3 Likes

This does seem like the best solution with the tools at hand. Thanks, appreciate the suggestion. :pray:

1 Like

Well, there is another solution - use MV2 for the Firefox :slight_smile:.

It pains me to say it but currently I see no good reason to use MV3 in Firefox. As you can see it complicates things a lot, not to mention other issues (like missing/broken API). Also MV3 won’t work in current Firefox ESR 102.

In any case, there is no deadline yet for MV2 in Firefox and even in Chrome the deadline is being moved over and over with many problems unresolved. So using MV2 for new extension is completely fine.

1 Like

Yeah, MV3 does complicate things. We considered moving to MV2, but decided to embrace the future, even with the pains it brings.

The largest blocker is that the Chrome Web Store will no longer accept new MV2 extensions. If we use MV3 in Chrome and MV2 in Firefox, we have to account for the different APIs. Would like to avoid that and keep the code agnostic, but we may consider it if the user experience is unacceptable.

Good to know! I wasn’t aware of that. :pray:

Maintaining both MV2/3 may not be a problem since most API didn’t change. And some of those that did change like “scripting” is also available in MV2. I have most of my many addons in MV3 in Chrome/Edge and in MV2 in Firefox/Safari/Thunderbird. And I’m using the same source code - apart from manifest files, those are unique for each build.

1 Like

You’re right. I switched over to Manifest V2, and it only took a few small changes to the manifest. Thank you for encouraging me to try it out. :slightly_smiling_face:

Out of curiosity, do you know off-hand if there is a rationale for not allowing the use of browser.permissions in a devtools context? I’m wondering if this might be a good feature request to submit to bugzilla.

1 Like

You mean the error that it can be called only from the user action? :smiley:
Yeah, that’s pretty annoying. Usually I end up writing something stupid like:

document.body.onclick = e => browser.permissions...

But sure, anything that can make your life easier is a good candidate for a bugzilla issue. Just don’t have high hopes :slight_smile:, people there are busy with many other issues.

2 Likes