Why browser.downloads.dowload hits into "undefined is not an object" error for Safari extension?

510 Views Asked by At

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.

0

There are 0 best solutions below