downloads.onChanged
The onChanged()
event of the downloads
API is fired when any of a downloads.DownloadItem
's properties changes (except for bytesReceived
).
The listener is passed a downloadDelta
as a parameter — an object containing the downloadId
of the downloads.DownloadItem
object in question, plus the status of all the properties that changed.
Syntax
browser.downloads.onChanged.addListener(listener)
browser.downloads.onChanged.removeListener(listener)
browser.downloads.onChanged.hasListener(listener)
Events have three functions:
-
addListener(callback)
-
Adds a listener to this event.
-
removeListener(listener)
-
Stop listening to this event. The listener
argument is the listener to remove.
-
hasListener(listener)
-
Check whether a given listener
is registered for this event. Returns true
if it is listening, false
otherwise.
Parameters
-
callback
-
A callback function that will be called when this event occurs. This function will be passed the following arguments:
-
downloadDelta
-
An object
representing the downloads.DownloadItem
object that changed, and the status of all the properties that changed in it. See the downloadDelta section for more details.
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
onChanged |
Yes |
79 |
47 |
? |
Yes |
No |
? |
? |
48–79 |
? |
No |
? |
Examples
Log a message when downloads complete:
function handleChanged(delta) {
if (delta.state && delta.state.current === "complete") {
console.log(`Download ${delta.id} has completed.`);
}
}
browser.downloads.onChanged.addListener(handleChanged);