Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/downloads/erase/index.md
6586 views
---
title: downloads.erase() slug: Mozilla/Add-ons/WebExtensions/API/downloads/erase page-type: webextension-api-function tags: - API - Add-ons - Extensions - Method - Non-standard - Reference - WebExtensions - downloads - erase browser-compat: webextensions.api.downloads.erase
---

{{AddonSidebar()}}

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

To remove the files from disk, you need to use {{WebExtAPIRef("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 {{WebExtAPIRef("downloads.removeFile()")}} before you call erase(). If you try it the other way around you'll get an error when calling {{WebExtAPIRef("downloads.removeFile()")}}, because it no longer exists according to the browser.

Syntax

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

Parameters

  • query

    • : A {{WebExtAPIRef('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 {{WebExtAPIRef("downloads.DownloadItem", "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

{{Compat}}

Examples

Erase the most recent download:

function onErased(ids) { console.log(`Erased: ${ids}`); } function onError(error) { console.log(`Error erasing item: ${error}`); } let 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}`); } let erasing = browser.downloads.erase({}); erasing.then(onErased, onError);

{{WebExtExamples}}

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