downloads.erase()

The erase() function of the downloads API erases matching DownloadItems from the browser's download history, without deleting the downloaded files from disk.

To remove the files from disk, you need to use downloads.removeFile().

This is an asynchronous function that returns a Promise.

Note: If you want to remove a downloaded file from disk and erase it from history, you have to call downloads.removeFile() before you call erase(). If you try it the other way around you'll get an error when calling downloads.removeFile(), because it no longer exists according to the browser.

Syntax

var erasing = browser.downloads.erase(
  query                    // DownloadQuery
)

Parameters

query
A downloads.DownloadQuery object.

Return value

A Promise. If the call was successful, the promise will be fulfilled with an array of integers representing the ids of the erased DownloadItems. If no items matching the query parameter could be found, the array will be empty. If the call failed, the promise will be rejected with an error message.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
Basic supportChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48

Legend

Full support  
Full support
No support  
No support

Examples

Erase the most recent download:

function onErased(ids) {
  console.log(`Erased: ${ids}`);
}

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

var erasing = browser.downloads.erase({
  limit: 1,
  orderBy: ["-startTime"]
});

erasing.then(onErased, onError);

Erase everything:

function onErased(ids) {
  console.log(`Erased: ${ids}`);
}

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

var erasing = browser.downloads.erase({});
erasing.then(onErased, onError);

Example extensions

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