Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/downloads/onchanged/index.md
6581 views
------{{AddonSidebar()}}
The onChanged() event of the {{WebExtAPIRef("downloads")}} API is fired when any of a {{WebExtAPIRef('downloads.DownloadItem')}}'s properties changes (except for bytesReceived).
The listener is passed a downloadDelta as a parameter — an object containing the downloadId of the {{WebExtAPIRef('downloads.DownloadItem')}} object in question, plus the status of all the properties that changed.
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:
downloadDelta: An
objectrepresenting the {{WebExtAPIRef('downloads.DownloadItem')}} object that changed, and the status of all the properties that changed in it. See the downloadDelta section for more details.
Additional objects
downloadDelta
The downloadDelta object has the following properties available:
id: An
integerrepresenting theidof the {{WebExtAPIRef('downloads.DownloadItem')}} that changed.
url{{optional_inline}}: A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
url.
filename{{optional_inline}}: A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
filename.
danger{{optional_inline}}: A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
danger.
mime{{optional_inline}}: A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
mime.
startTime{{optional_inline}}: A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
startTime.
endTime{{optional_inline}}: A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
endTime.
state{{optional_inline}}: A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
state.
canResume{{optional_inline}}: A {{WebExtAPIRef('downloads.BooleanDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
canResumestatus.
paused{{optional_inline}}: A {{WebExtAPIRef('downloads.BooleanDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
pausedstatus.
error{{optional_inline}}: A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
errorstatus.
totalBytes{{optional_inline}}: A {{WebExtAPIRef('downloads.DoubleDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
totalBytes.
fileSize{{optional_inline}}: A {{WebExtAPIRef('downloads.DoubleDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
fileSize.
exists{{optional_inline}}: A {{WebExtAPIRef('downloads.BooleanDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s
existsstatus.
Browser compatibility
{{Compat}}
Examples
Log a message when downloads complete:
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.downloadsAPI.