permissionsfirefox-addonfirefox-addon-webextensionsmanifest.json

Firefox extension Manifest v3 - request permission to "access your data for all websites" at runtime


Can a Manifest v3 Firefox extension request the "Access your data for all websites" permission from the user at runtime?

This option is usually managed in the firefox about:addons built-in page:

Firefox about:addons page

Some features of my extension require this permission to work, and I want to prompt the user to grant it if it hasn't been granted yet.

The desired workflow is as follows:

When the user clicks a button to trigger a feature that requires this permission, the extension checks if it has the permission to access data for all websites.

If the permission has not been granted yet, the extension should request it from the user. If the permission has already been granted, the feature should be triggered.

I have tried using the browser.permissions API, but I could not find a way to request this specific permission at runtime.

Is there any other way to request this permission from the user at runtime, or is it simply not possible?

Edit:

Not sure if this is the intended behavior, but sending a permission request with only "origins" and no "permission" key specified seems to work:

browser.permissions.request({origins: ['<all_urls>']})

Solution

  • Solution

    Sending a permission request with the "origins" parameter set to "<all_urls>" is equivalent to requesting the "Access your data for all websites" permission:

    browser.permissions.request({origins: ['<all_urls>']})
    

    Why does it work?

    The MDN Permissions documentation states that both origins and permissions parameters are optional.

    By setting origins: <all_urls>, the extension is effectively requesting permission to "Access your data for all websites".

    The presence of this permission can be checked by invoking browser.permissions.getAll() and checking the presence of <all_urls> in permissions.origins.

    Implementation example:

    const hasAllUrlsPermission = () => {
        return browser.permissions.getAll()
            .then(permissions => permissions.origins.indexOf("<all_urls>") > - 1);
    }
    

    Compatibility

    This solution was tested on Firefox v.112.

    About <all_urls>

    Granting the <all_urls> permission in a Firefox extension can pose a risk to security and privacy.

    For this reason, Mozilla Extension Workshop recommends to

    Avoid host permission <all_urls> if you can.

    Where possible and applicable, their recommandation is to

    Use activeTab rather than tabs and host permissions