downloads

Interact with the browser's download manager. You can use this module to download files, cancel, pause, resume downloads, and show downloaded files in the file manager.

To use this API you need to have the "downloads" permission.

Types

downloads.FilenameConflictAction
downloads.InterruptReason
downloads.DangerType
downloads.State
downloads.DownloadItem
downloads.StringDelta
downloads.DoubleDelta
downloads.BooleanDelta
downloads.DownloadTime
downloads.DownloadQuery

Functions

downloads.download()
Download a URL. If the URL uses the HTTP[S] protocol, then the request will include all cookies currently set for its hostname. If both filename and saveAs are specified, then the Save As dialog will be displayed, pre-populated with the specified filename. If the download started successfully, callback will be called with the new DownloadItem's downloadId. If there was an error starting the download, then callback will be called with downloadId=undefined and runtime.lastError will contain a descriptive string. The error strings are not guaranteed to remain backwards compatible between releases. You must not parse it.
downloads.search()
Find DownloadItems. Set query to the empty object to get all DownloadItems. To get a specific DownloadItem, set only the id field.
downloads.pause()
Pause the download. If the request was successful the download is in a paused state. Otherwise runtime.lastError contains an error message. The request will fail if the download is not active.
downloads.resume()
Resume a paused download. If the request was successful the download is in progress and unpaused. Otherwise runtime.lastError contains an error message. The request will fail if the download is not active.
downloads.cancel()
Cancel a download. When callback is run, the download is cancelled, completed, interrupted or doesn't exist anymore.
downloads.getFileIcon()
Retrieve 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 operating system or toolkit depending on the 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. If a file icon cannot be determined, runtime.lastError will contain an error message.
downloads.open()
Open the downloaded file.
downloads.show()
Show the downloaded file in its folder in a file manager.
downloads.showDefaultFolder()
downloads.erase()
Erase matching DownloadItems from history
downloads.removeFile()
downloads.acceptDanger()
Prompt the user to either accept or cancel a dangerous download. acceptDanger() does not automatically accept dangerous downloads.
downloads.drag()
Initiate dragging the file to another application.
downloads.setShelfEnabled()

Events

downloads.onCreated
This event fires with the DownloadItem object when a download begins.
downloads.onErased
Fires with the downloadId when a download is erased from history.
downloads.onChanged
When any of a DownloadItem's properties except bytesReceived changes, this event fires with the downloadId and an object containing the properties that changed.

Browser compatibility

EdgeFirefoxChromeOpera
BooleanDelta?47.0Yes33
DangerType?47.0Yes33
DoubleDelta?47.0Yes33
DownloadItem?47.0Yes33
DownloadQuery?47.0Yes33
DownloadTime?47.0Yes33
FilenameConflictAction?47.0Yes33
InterruptReason?47.0Yes33
State?47.0Yes33
StringDelta?47.0Yes33
acceptDanger?NoYes33
cancel?48.0Yes33
download?47.0Yes33
drag?NoYes33
erase?48.0Yes33
getFileIcon?NoYes33
onChanged?47.0Yes33
onCreated?48.0Yes33
onErased?48.0Yes33
open?48.0Yes33
pause?48.0Yes33
removeFile?48.0Yes33
resume?48.0Yes33
search?47.0Yes33
setShelfEnabled?NoYes33
show?48.0Yes33
showDefaultFolder?48.0Yes33
Firefox
BooleanDelta48.0
DangerType48.0
DoubleDelta48.0
DownloadItem48.0
DownloadQuery48.0
DownloadTime48.0
FilenameConflictAction48.0
InterruptReason48.0
State48.0
StringDelta48.0
acceptDangerNo
cancel48.0
download48.0
dragNo
erase48.0
getFileIconNo
onChanged48.0
onCreated48.0
onErased48.0
open48.0
pause48.0
removeFile48.0
resume48.0
search48.0
setShelfEnabledNo
show48.0
showDefaultFolder48.0

Chrome incompatibilities

  • Firefox does not support:
    • pause()
    • getFileIcon()
    • resume()
    • show()
    • removeFile()
    • cancel()
    • drag()
    • erase()
    • acceptDanger()
    • showDefaultFolder()
    • setShelfEnabled()
    • open()
    • onCreated
    • onErased

Acknowledgements

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

Document Tags and Contributors

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