0

While trying to port my extension to Safari (using xcrun safari-web-extension-converter) from Firefox add-on, the browser.downloads.download implementation in my extension to download the user options stored hits into following error:

TypeError: undefined is not an object (evaluating 'browser.downloads.download')

Following lists my implementation for downloading the user options as .csv file:

var enableDebug = 1;
// Function to download CSV file
function downloadCSV(csv, file_name) {
  try {
    var blob = new Blob([csv], {
      type: "text/csv;charset=utf-8"
    });
    browser.downloads.download({
      url: URL.createObjectURL(blob),
      filename: file_name,
      saveAs: true
    });
  } catch (err) {
    if (enableDebug === 1) {
      console.log(err);
    }
  }
}

manifest.json permissions:

"permissions": ["menus", "storage", "unlimitedStorage", "downloads"]

The Safari version being used is 15.4. Looking around the web had given following links which seem relevant, but i'm quite not sure if the issues mentioned in these links are the ones which are causing failure in my case:

browser.downloads API for Safari Web Extensions

Safari error undefined is not an object

I did try with adding the following in entitlements file of XCode, but it didn't help either:

com.apple.security.files.downloads.read-write

Any help to understand the cause and probable solution would be highly appreciated.

bprasanna
  • 2,423
  • 3
  • 27
  • 39
  • 1
    First link that you provided says that this api is not supported in Safari. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/downloads/download#browser_compatibility mdn says the same – Konrad May 15 '22 at 18:41
  • 1
    @KonradLinkowski Thank you very much for pointing out the compatibility matrix. I have missed to refer this. Thank you, it is confirmed that there is no support for download API in Safari. – bprasanna May 18 '22 at 08:03

0 Answers0