Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/downloads/oncreated/index.md
6581 views
------{{AddonSidebar()}}
The onCreated() event of the {{WebExtAPIRef("downloads")}} API fires when a download begins, i.e. when {{WebExtAPIRef("downloads.download()")}} is successfully invoked.
The listener is passed 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
function: A callback function that will be called when this event occurs. This function will be passed the following arguments:
downloadItem: The {{WebExtAPIRef('downloads.DownloadItem')}} object in question.
Browser compatibility
{{Compat}}
Examples
Log the URL of items as they are downloaded:
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.downloadsAPI.