This page was translated from English by the community.Learn more and join the MDN Web Docs community.
downloads
Позволяет расширениям взаимодействовать с менеджером загрузки браузера. Этот модуль API можно использовать для загрузки, отмены, приостановки, возобновления загрузки файлов и отображения загруженных файлов в файловом менеджере.
Для использования этого API вам необходимо указать "downloads"API permission в вашемmanifest.json файле.
In this article
Types
downloads.FilenameConflictActionОпределяет действия в случае, если имя загружаемого файла конфликтует с именем существующего файла.
downloads.InterruptReasonDefines a set of possible reasons why a download was interrupted.
downloads.DangerTypeDefines a set of common warnings of possible dangers associated with downloadable files.
downloads.StateDefines different states that a current download can be in.
downloads.DownloadItemRepresents a downloaded file.
downloads.StringDeltaRepresents the difference between two strings.
downloads.DoubleDeltaRepresents the difference between two doubles.
downloads.BooleanDeltaRepresents the difference between two booleans.
downloads.DownloadTimeRepresents the time a download took to complete.
downloads.DownloadQueryDefines a set of parameters that can be used to search the downloads manager for a specific set of downloads.
Functions
downloads.download()Downloads a file, given its URL and other optional preferences.
downloads.search()Queries the
DownloadItemsavailable in the browser's downloads manager, and returns those that match the specified search criteria.downloads.pause()Pauses a download.
downloads.resume()Resumes a paused download.
downloads.cancel()Cancels a download.
downloads.getFileIcon()Retrieves an icon for the specified download.
downloads.open()Opens the downloaded file with its associated application.
downloads.show()Opens the platform's file manager application to show the downloaded file in its containing folder.
downloads.showDefaultFolder()Opens the platform's file manager application to show the default downloads folder.
downloads.erase()Erases matching
DownloadItemsfrom the browser's download history, without deleting the downloaded files from disk.downloads.removeFile()Removes a downloaded file from disk, but not from the browser's download history.
downloads.acceptDanger()Prompts the user to accept or cancel a dangerous download.
downloads.drag()Initiates dragging the downloaded file to another application.
downloads.setShelfEnabled()Enables or disables the gray shelf at the bottom of every window associated with the current browser profile. The shelf will be disabled as long as at least one extension has disabled it.
Events
downloads.onCreatedFires with the
DownloadItemobject when a download begins.downloads.onErasedFires with the
downloadIdwhen a download is erased from history.downloads.onChangedWhen any of a
DownloadItem's properties exceptbytesReceivedchanges, this event fires with thedownloadIdand an object containing the properties that changed.
Совместимость с браузерами
Example extensions
Примечание:Этот API основан на Chromium APIchrome.downloads.