downloads

启用与浏览器的下载管理器交互的扩展。你可以使用这个 API 模块来下载文件、取消、暂停、恢复下载和在文件管理器中显示下载的文件。

为使用此 API,你需要在你的 manifest.json 文件中声明 "downloads" API 权限

Types

downloads.FilenameConflictAction
定义当一个下载的文件与现存的文件命名冲突时要做什么。
downloads.InterruptReason
定义一系列中断下载的可能理由。
downloads.DangerType
定义一组与可下载文件相关的潜在危险的常见警告。
downloads.State
定义当前下载可能处于的不同状态。
downloads.DownloadItem
代表下载的文件。
downloads.StringDelta
表示两个字符串之间的差异。
downloads.DoubleDelta
代表两个双精度浮点数之间的差异。
downloads.BooleanDelta
代表两个布尔数之间的差异。
downloads.DownloadTime
代表一个下载将会花费的时间。
downloads.DownloadQuery
定义一组参数,可用于在下载管理器中搜索一组特定的下载。

Functions

downloads.download()
下载一个文件,给出它的 URL 和其他可选的参数。
downloads.search()
查询 DownloadItems 是否在浏览器的下载管理器中可用,返回匹配指定的搜索标准的条目。
downloads.pause()
暂停一个下载。
downloads.resume()
恢复一个暂停的下载。
downloads.cancel()
取消一个下载。
downloads.getFileIcon()
检索指定下载的图标。
downloads.open()
用下载的文件相关联的程序打开它。
downloads.show()
打开当前平台的文件管理应用来在它包含的文件夹中显示下载的文件。
downloads.showDefaultFolder()
用当前平台的文件管理应用显示默认下载文件夹。
downloads.erase()
擦除浏览器的下载历史中匹配 DownloadItems 的下载记录,不会在磁盘中删除文件。
downloads.removeFile()
从磁盘中移除下载的文件,但不从浏览器的下载历史中去除。
downloads.acceptDanger()
提示用户接受或取消危险的下载。
downloads.drag()
   将下载的文件拖动到另一个应用程序。
downloads.setShelfEnabled()
启用或禁用与当前浏览器配置文件关联的每个窗口底部的灰色架子。 只要至少一个扩展名已禁用该架子,它就会被禁用。

Events

downloads.onCreated
当一个下载开始时被 DownloadItem 对象触发。
downloads.onErased
当一个下载从历史中擦除时被 Fires with the downloadId 触发。
downloads.onChanged
当任意一个 DownloadItem 的属性期望 bytesReceived 改变时,此事件被这个 `downloadId` 和包含了变化属性的对象触发。

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
BooleanDeltaChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
DangerTypeChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
DoubleDeltaChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
DownloadQueryChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
DownloadTimeChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
FilenameConflictActionChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
InterruptReasonChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
StateChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
StringDeltaChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
acceptDangerChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
cancelChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
downloadChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
dragChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
eraseChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
getFileIconChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android No support No
onChangedChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
onCreatedChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
onErasedChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
openChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
pauseChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
removeFileChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
resumeChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
searchChrome Full support YesEdge No support NoFirefox Full support 47Opera Full support YesFirefox Android Full support 48
setShelfEnabledChrome Full support YesEdge No support NoFirefox No support NoOpera Full support YesFirefox Android No support No
showChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48
showDefaultFolderChrome Full support YesEdge No support NoFirefox Full support 48Opera Full support YesFirefox Android Full support 48

Legend

Full support  
Full support
No support  
No support

Example extensions

Acknowledgements

This API is based on Chromium's chrome.downloads API.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.