docs.rodeo

MDN Web Docs mirror

downloads.onChanged

{{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

browser.downloads.onChanged.addListener(listener)
browser.downloads.onChanged.removeListener(listener)
browser.downloads.onChanged.hasListener(listener)

Events have three functions:

addListener syntax

Parameters

Additional objects

downloadDelta

The downloadDelta object has the following properties available:

Browser compatibility

{{Compat}} 

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);

{{WebExtExamples}} 

[!NOTE] This API is based on Chromium’s chrome.downloads API.

In this article

View on MDN