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
let gettingIcon = browser.downloads.getFileIcon(
downloadId, // integer
options // optional object
)
Parameters
downloadId
-
An
integer
representing the ID of the download. options
Optional-
An options
object
representing preferences for the icon to be retrieved. It can take the following properties:size
Optional-
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
BCD tables only load in the browser
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;
let gettingIcon = browser.downloads.getFileIcon(latestDownloadId);
gettingIcon.then(gotIcon, onError);
}
}
let searching = browser.downloads.search({
limit: 1,
orderBy: ["-startTime"],
});
searching.then(getIcon, onError);
Example extensions
Note:
This API is based on Chromium's chrome.downloads
API.