downloads.open()

The open() function of the downloads API opens the downloaded file with its associated application.

A downloads.onChanged event will fire when the item is opened for the first time.

Note: To use this function in your WebExtension you must ask for the "downloads.open" manifest permission, as well as the "downloads" permission.

Syntax

chrome.downloads.open(
  downloadId,      // integer
  function() {...} // optional function
)

This API is also available as browser.downloads.open() in a version that returns a promise.

Parameters

downloadId
An integer representing the id of the downloads.DownloadItem you want to open.
function() {}Optional
An optional callback function that gets invoked, with no parameters, when the open() call has completed.

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes No 48.0 48.0 33

Examples

The following snippet shows two buttons, "download" and "open". The first button when clicked initiates a download using downloads.download(). Once the download has started, the second button can be pressed to open the file with its associated application.

var downloadBtn = document.querySelector('.download');
var openBtn = document.querySelector('.open');

downloadBtn.onclick = function() {
  chrome.downloads.download({ url : 'http://www.example.com/myBigVideo.mp4'},
  callback);

  function callback(downloadId) {
    if(chrome.runtime.lastError) {
      console.log(chrome.runtime.lastError);
    } else {
      openBtn.onclick = function() {
        chrome.downloads.open(downloadId, function() {
          console.log('File opened');
        });
      }
    }
  }
}

Example add-ons

Acknowledgements

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: Makyen, wbamberg, chrisdavidmills
 Last updated by: Makyen,