MDN wants to learn about developers like you:


The download() function of the downloads API downloads a file, given its URL and other optional preferences.

  • If the specified 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.

This is an asynchronous function that returns a Promise.


var downloading =
  options                   // object


An object specifying what file you wish to download, and any other preferences you wish to set concerning the download. It can contain the following properties:
A string representing the URL to download.
A string representing a file path relative to the default downloads directory — this provides the location where you want the file to be saved, and what filename you want to use. Absolute paths, empty paths, and paths containing back-references (../) will cause an error. If omitted, this value will default to the filename already given to the download file, and a location immediately inside the downloads directory.
A string representing the action you want taken if there is a filename conflict, as defined in the downloads.FilenameConflictAction type (defaults to "uniquify" when it is not specified).
A boolean that specifies whether to provide a file chooser dialog to allow the user to select a filename (true), or not (false).
A string representing the HTTP method to use if the url uses the HTTP[S] protocol. This may be either "GET" or "POST".
An array of objects representing extra HTTP headers to send with the request if the URL uses the HTTP[s] protocol. Each header is represented as a dictionary object containing the keys name and either value or binaryValue, restricted to those allowed by XMLHttpRequest.
A string representing the post body of the request.

Return value

A Promise. If the download started successfully, the promise will be fulfilled with the id of the new downloads.DownloadItem. Otherwise the promise will be rejected with an error message.

Browser compatibility

ChromeEdgeFirefoxFirefox for AndroidOpera
Basic supportYesNo4748Yes


The following snippet attempts to download an example file, also specifying a filename and location to save it in, and the uniquify conflictAction option.

function onStartedDownload(id) {
  console.log(`Started downloading: ${id}`);

function onFailed(error) {
  console.log(`Download failed: ${error}`);

var downloadUrl = "";

var downloading ={
  url : downloadUrl,
  filename : 'my-image-again.png',
  conflictAction : 'uniquify'

downloading.then(onStartedDownload, onFailed);


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.

Document Tags and Contributors

 Contributors to this page: lgreco, CaemU, wbamberg, Makyen, chrisdavidmills, aswan
 Last updated by: lgreco,