downloads.open()

The open() function of the downloads API opens the downloaded file with its associated application. A downloads.onChanged event fires when the item is opened for the first time.

To use this function in your extension you must ask for the "downloads.open" manifest permission, as well as the "downloads" permission. Also, you can only call this function from inside the handler for a user action.

This is an asynchronous function that returns a Promise.

Syntax

js
let opening = browser.downloads.open(
  downloadId      // integer
)

Parameters

downloadId

An integer representing the id of the downloads.DownloadItem you want to open.

Return value

A Promise. If the request is successful, the promise is fulfilled with no arguments. If the request failed, the promise is rejected with an error message.

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
open

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

Examples

This example opens the most recently downloaded item:

js
function onOpened() {
  console.log(`Opened download item`);
}

function onError(error) {
  console.log(`Error opening item: ${error}`);
}

function openDownload(downloadItems) {
  if (downloadItems.length > 0) {
    let opening = browser.downloads.open(downloadItems[0].id);
    opening.then(onOpened, onError);
  }
}

let searching = browser.downloads.search({
  limit: 1,
  orderBy: ["-startTime"],
});

searching.then(openDownload, onError);

Example extensions

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