Closed Bug 1910498 Opened 2 months ago Closed 2 months ago

browser.permissions.request fails when used after a promise

Categories

(WebExtensions :: Untriaged, defect)

Firefox 128
defect

Tracking

(firefox128 affected, firefox129 affected, firefox130 affected)

RESOLVED DUPLICATE of bug 1398833
Tracking Status
firefox128 --- affected
firefox129 --- affected
firefox130 --- affected

People

(Reporter: tom_xyz, Unassigned)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0

Steps to reproduce:

Add "downloads" as optional permission in manifest.json:

  "optional_permissions": [
    "downloads"
  ],

Actual results:

When you try to use the Downloads API, you do not get a prompt to grant this permission. Even when you manually enable the permission, the download still fails. Here's a recording:

https://screenrec.com/share/OS7aFCX1wY

Expected results:

If it's an optional permission, you should get a prompt to enable this permission like in Chrome/Edge. Here's the experience in Chrome/Edge, and it's what should have happened:

https://screenrec.com/share/sZkLF9hd1w

Steps to reproduce:

  1. Install Lightning Autofill (https://addons.mozilla.org/firefox/addon/lightning-autofill/)
  2. Go to Options / Sync tab
  3. Click Export button

ISSUE: You get a "Failed to export your data because you did not grant the 'downloads' permission" error, and there's no way to grant this permission.

Try the same steps in Chrome or Edge -- it works correctly (you get a prompt to allow you to grant the permission).

Chrome: https://chrome.google.com/webstore/detail/autofill/nlmmgnhgdeffjkdckmikfpnddkbbfkkk
Edge: https://microsoftedge.microsoft.com/addons/detail/lkfeipbjpgibcbhhciamknhfdpjemfke

Not sure if it's related, but I don't see "downloads" listed here:

https://developer.mozilla.org/docs/Web/API/Permissions_API

UPDATE: I made "downloads" a required permission, but still cannot use the Downloads API :(

  "permissions": [
    "downloads"
  ],

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

API code:

  browser.permissions.request({permissions:['downloads']}, function(granted) {
    // The callback argument will be `true` if the user granted the permissions
    if (granted) {
      // Download file
    } else {
      // Show error
    }
  });

Please provide a small snippet to reproduce the issue.

Note: if all you want is to provide a file as a download, then you can also use <a download> to offer data as a download. This does not require any additional permissions, only user interaction.

Flags: needinfo?(tom_xyz)

I cannot use <a download> because I'm saving a blob. In any case, I think I identified the root cause: promises.

Steps to reproduce:

  1. Install _minimal-firefox.zip in Firefox
  2. Open Options
  3. Click "Export Data" button -- works fine
  4. Click "Export Data after Promise" button -- fails

Now repeat the same steps above in Chrome with _minimal-chrome.zip -- it works as expected. It appears in Firefox the grant permissions functionality breaks when used with a promise.

Flags: needinfo?(tom_xyz)
Summary: Issue with "downloads" optional permissions in extensions → browser.permissions.request fails when used after a promise

Hello,

I reproduced the issue on the latest Nightly (130.0a1/20240730164742), Beta (129.0/20240729133145) and Release (128.0.3/20240725162350) under Windows 10 and Ubuntu 22.04 LTS using the STR from Comment 6 and the extension from Comment 7.

Clicking the “Export Data” button on the extension options page prompts the user to grant an additional permission “Download files and read and modify the browser’s download history” and if allowed, a file is downloaded.
On the other hand, clicking the “Export Data after Promise” button will not prompt the user to grant any additional permissions and will not download any file. An error is logged to console as well Unchecked lastError value: Error: permissions.request may only be called from a user input handler options.js:15

Status: UNCONFIRMED → NEW
Ever confirmed: true

(In reply to Tom Doan from comment #6)

I cannot use <a download> because I'm saving a blob.

You can turn a Blob in a URL with URL.createObjectURL - https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static

In any case, I think I identified the root cause: promises.
It appears in Firefox the grant permissions functionality breaks when used with a promise.

That makes this bug a duplicate of bug 1398833.

Status: NEW → RESOLVED
Closed: 2 months ago
Duplicate of bug: 1398833
Resolution: --- → DUPLICATE

You can turn a Blob in a URL with URL.createObjectURL - https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static

That's huge -- thanks Rob 🙏

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: