Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/downloads/onerased/index.md
6581 views
------{{AddonSidebar()}}
The onErased() event of the {{WebExtAPIRef("downloads")}} API fires when a download is erased from the browser history.
The listener is passed the downloadId of the {{WebExtAPIRef('downloads.DownloadItem')}} object in question as a parameter.
Syntax
Events have three functions:
addListener(callback): Adds a listener to this event.
removeListener(listener): Stop listening to this event. The
listenerargument is the listener to remove.
hasListener(listener): Check whether a given
listeneris registered for this event. Returnstrueif it is listening,falseotherwise.
addListener syntax
Parameters
callback: A callback function that will be called when this event occurs. This function will be passed the following arguments:
downloadId: An
integerrepresenting theidof the {{WebExtAPIRef('downloads.DownloadItem')}} that was erased.
Browser compatibility
{{Compat}}
Examples
Add a listener for onErased events, then erase the most recent download:
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.downloadsAPI.