Movatterモバイル変換


[0]ホーム

URL:


  1. Mozilla
  2. Add-ons
  3. Browser extensions
  4. JavaScript APIs
  5. downloads
  6. downloads.getFileIcon()

downloads.getFileIcon()

ThegetFileIcon() function of thedownloads API retrieves an icon for the specified download.

For new downloads, file icons are available after thedownloads.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 aPromise.

Syntax

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

Parameters

downloadId

Aninteger representing the ID of the download.

optionsOptional

An optionsobject representing preferences for the icon to be retrieved. It can take the following properties:

sizeOptional

Aninteger 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

APromise. 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.

Examples

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

js
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

Browser compatibility

Note:This API is based on Chromium'schrome.downloads API.

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp