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
.
var gettingIcon = browser.downloads.getFileIcon( downloadId, // integer options // optional object )
downloadId
integer
representing the ID of the download.options
Optional
object
representing preferences for the icon to be retrieved. It can take the following properties:size
Optional
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.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.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
getFileIcon |
Yes |
79 |
48 |
? |
Yes |
No |
? |
? |
No |
? |
? |
? |
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);
Note: 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.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/downloads/getFileIcon