downloads.download()

Download a file, given its URL.

If the URL uses the HTTP or HTTPS 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 stay the same between releases.

Syntax

browser.downloads.download(
  options,                   // object
  function(downloadId) {...} // optional function
)

Parameters

options
object. What to download and how.
url
string. The URL to download.
filenameOptional
string. A file path relative to the Downloads directory to contain the downloaded file.
conflictActionOptional
downloads.FilenameConflictAction.
saveAsOptional
boolean. Use a file-chooser to allow the user to select a filename.
methodOptional
string. The HTTP method to use if the URL uses the HTTP[S] protocol.
headersOptional
array of object. Extra HTTP headers to send with the request if the URL uses the HTTP[s] protocol. Each header is represented as a dictionary containing the keys name and either value or binaryValue, restricted to those allowed by XMLHttpRequest.
bodyOptional
string. Post body.
callbackOptional
function. The function is passed the following arguments:
downloadId
integer.

Additional objects

headers

name
string. Name of the HTTP header.
value
string. Value of the HTTP header.

Browser compatibility

EdgeFirefoxChromeOpera
Basic support?47.0Yes33
Firefox
Basic support48.0

Examples

Acknowledgements

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

Document Tags and Contributors

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