大网数据广告活动
Web 标准与前端开发

`browsingContext.downloadEnd` event

· 52CE 我爱测

The `browsingContext.downloadEnd` event of the `browsingContext` module fires when a file download finishes, either because it completed or because it was canceled.

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.downloadWillBegin event, so you can correlate the two.
  • filepath
    • : A string that contains the path where the browser saved the downloaded file, or null if the path is not available. This field is included only when the status field value is "complete".
  • navigation
    • : A string that contains the UUID that uniquely identifies the associated navigation, or null if the download is not associated with a navigation. If the navigation was started using the browsingContext.navigate or browsingContext.reload command, this ID matches the navigation value in the command's response. The same ID is shared by other events that fire for this navigation, such as browsingContext.navigationStarted and network module 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

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。