downloads.getFileIcon()

The getFileIcon() function of the downloads API retrieves an icon for the specified download.

For new downloads, file icons are available after the downloads.onCreated event has been received. The image returned by this function while a download is in progress may be different from the image returned after the download is complete.

Icon retrieval is done by querying the underlying platform. The icon that is returned will therefore depend on a number of factors including state of the download, platform, registered file types and visual theme.

This is an asynchronous function that returns a Promise.

Syntax

var gettingIcon = browser.downloads.getFileIcon(
  downloadId,           // integer
  options               // optional object
)

Parameters

downloadId
An integer representing the ID of the download.
optionsOptional
An options object representing preferences for the icon to be retrieved. It can take the following properties:
sizeOptional
An integer representing the size of the icon. The returned icon's size will be the provided size squared (in pixels). If omitted, the default size for the icon is 32x32 pixels.

Return value

A Promise. If the request succeeds, the promise will be fulfilled with a string representing the absolute URL of the icon. If the request fails, the promise will be rejected with an error message.

Browser compatibility

ChromeEdgeFirefoxFirefox for AndroidOpera
Basic supportYesNoNoNoYes

Examples

This example logs the icon URL for the most recent download:

function gotIcon(iconUrl) {
  console.log(iconUrl);
}
function onError(error) {
  console.log(`Error: ${error}`);
}
function getIcon(downloadItems) {
    if (downloadItems.length > 0) {
      latestDownloadId = downloadItems[0].id;
      var gettingIcon = browser.downloads.getFileIcon(latestDownloadId);
      gettingIcon.then(gotIcon, onError);
    }
  }
var searching = browser.downloads.search({
  limit: 1,
  orderBy: ["-startTime"]
});
searching.then(getIcon, onError);

Example extensions

Acknowledgements

This API is based on Chromium's chrome.downloads API.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

 Contributors to this page: wbamberg, Makyen, chrisdavidmills
 Last updated by: wbamberg,