browsingContext.downloadEnd event
The browsingContext.downloadEnd event of the browsingContext module fires when a file download finishes, either because it completed or because it was canceled.
Event data
The params field in the event notification is an object that includes a status field.
The value of status determines which additional fields are present.
context-
A string that contains the ID of the context in which the download occurred.
download-
A string that contains the UUID that uniquely identifies this download. The same ID is included in the corresponding
browsingContext.downloadWillBeginevent, so you can correlate the two. filepathOptional-
A string that contains the path where the browser saved the downloaded file, or
nullif the path is not available. This field is included only when thestatusfield value is"complete". -
A string that contains the UUID that uniquely identifies the associated navigation, or
nullif the download is not associated with a navigation. If the navigation was started using thebrowsingContext.navigateorbrowsingContext.reloadcommand, this ID matches thenavigationvalue in the command's response. The same ID is shared by other events that fire for this navigation, such asbrowsingContext.navigationStartedandnetworkmodule events. status-
A string that indicates the result of the download. It has one of the following values:
"canceled": The download was canceled before it completed."complete": The download completed successfully.
timestamp-
A non-negative integer that represents the time when the event was fired, as milliseconds elapsed since the epoch.
url-
A string that contains the URL of the download.
Examples
>Receiving an event when a download completes
Assume you have a WebDriver BiDi connection, an active session, and a subscription to browsingContext.downloadEnd active.
Suppose a download finishes and the browser saves the file to disk. The browser then sends the following notification:
{
"type": "event",
"method": "browsingContext.downloadEnd",
"params": {
"context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
"download": "6bfa8781-e33c-4f2c-8e63-4d0f6dc5d1a1",
"filepath": "/home/user/Downloads/report.pdf",
"navigation": "0e2f4d20-8f0a-4de7-9749-1b12a0d6c8b0",
"status": "complete",
"timestamp": 1737033601500,
"url": "https://example.com/files/report.pdf"
}
}
Receiving an event when a download is canceled
Using the same connection, session, and subscription as in the previous example, suppose the type field of the downloadBehavior object passed to the browser.setDownloadBehavior command is set to "denied".
This causes the browser to reject the download rather than save it.
In this case, the browser sends the following notification:
{
"type": "event",
"method": "browsingContext.downloadEnd",
"params": {
"context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
"download": "6bfa8781-e33c-4f2c-8e63-4d0f6dc5d1a1",
"navigation": "0e2f4d20-8f0a-4de7-9749-1b12a0d6c8b0",
"status": "canceled",
"timestamp": 1737033601500,
"url": "https://example.com/files/report.pdf"
}
}
Specifications
| Specification |
|---|
| WebDriver BiDi> # event-browsingContext-downloadEnd> |
Browser compatibility
See also
browsingContext.downloadWillBegineventbrowser.setDownloadBehaviorcommandsession.subscribecommand