How to require permissions to be enabled in Firefox using Manifest v3?
Asked Answered
B

1

10

As of January 17, Firefox now supports Manifest v3 in Firefox 109.0.

I have an add-on I am testing with Manifest v3 and it requires access to a variable on reddit.com.

I want to make the "Access your data for sites in the *://reddit.com domain" permission required, since the extension does not work without it.

What needs to be done to make it so it does not show as optional since I want the user to not have to explicitly turn on the permission from the Permissions tab?

enter image description here

I want it show as required similar to this image (source):

enter image description here

Here's a trimmed down version of an example Manifest file that shows the permission as optional.

{
    "manifest_version": 3,
    "name": "Example",
    "description": "Example",
    "version": "3.16.1",
    "content_scripts": [
        {
            "run_at": "document_idle",
            "matches": ["*://*.reddit.com/"],
            "js": ["script.js"]
        }
    ]
}

I have tried adding "permissions": ["https://*.reddit.com/*"], but it still shows as optional.

I also tried "permissions": ["*://reddit.com"] and "host_permissions": ["*://reddit.com"] but nothing is causing it to be required.

I have a Chrome extension which is working with the same manifest v3 file.

Byelection answered 20/1, 2023 at 23:31 Comment(1)
This is probably a bug in Firefox or maybe they misunderstood that Chrome's plan for ManifestV3 was to allow the user choose when installing the extension whether to grant the required host permissions immediately or make them optional. This feature is not yet implemented in Chrome.Jamestown
I
2

The only solution I have found is to set optional permissions. https://developer.chrome.com/docs/extensions/reference/permissions/

I added the permission setting itself to the listener. Of course, I check beforehand that such permissions do not already exist.

    browser.action.onClicked.addListener((tab: Tab) => {
      browser.permissions.request({
        origins: ['*://*.reddit.com/']
      })
    });
Incomprehension answered 8/2, 2023 at 15:59 Comment(3)
Warning: if you have action.default_popup in manifest.json, browser.action.onClicked is never called. Hopefully I spared somebody else's time wandering around stackoverflow and MDN trying to figure out why browser.action.onClicked is never f*****g called!Wilinski
Where should I copy paste your code? manifest.json ?Mexicali
@Mexicali You need to add it to background scriptIncomprehension

© 2022 - 2024 — McMap. All rights reserved.