Permissions: downloads

Not allowed in: Content scripts, Devtools pages

_DownloadOptions
_DownloadOptionsHeaders
_GetFileIconOptions
_OnChangedDownloadDelta
BooleanDelta
DoubleDelta
DownloadItem
DownloadQuery
StringDelta
_DownloadOptionsMethod
DangerType
DownloadTime
FilenameConflictAction
InterruptReason
State
onChanged
onCreated
onErased
acceptDanger
cancel
download
drag
erase
getFileIcon
open
pause
removeFile
resume
search
setShelfEnabled
show
showDefaultFolder
_DownloadOptionsMethod: "GET" | "POST"

The HTTP method to use if the URL uses the HTTP[S] protocol.

DangerType:
    | "file"
    | "url"
    | "content"
    | "uncommon"
    | "host"
    | "unwanted"
    | "safe"
    | "accepted"

file: The download's filename is suspicious. url: The download's URL is known to be malicious. content: The downloaded file is known to be malicious. uncommon: The download's URL is not commonly downloaded and could be dangerous. safe: The download presents no known danger to the user's computer.

These string constants will never change, however the set of DangerTypes may change.

DownloadTime: string | Date

A time specified as a Date object, a number or string representing milliseconds since the epoch, or an ISO 8601 string

FilenameConflictAction: "uniquify" | "overwrite" | "prompt"
InterruptReason:
    | "FILE_FAILED"
    | "FILE_ACCESS_DENIED"
    | "FILE_NO_SPACE"
    | "FILE_NAME_TOO_LONG"
    | "FILE_TOO_LARGE"
    | "FILE_VIRUS_INFECTED"
    | "FILE_TRANSIENT_ERROR"
    | "FILE_BLOCKED"
    | "FILE_SECURITY_CHECK_FAILED"
    | "FILE_TOO_SHORT"
    | "NETWORK_FAILED"
    | "NETWORK_TIMEOUT"
    | "NETWORK_DISCONNECTED"
    | "NETWORK_SERVER_DOWN"
    | "NETWORK_INVALID_REQUEST"
    | "SERVER_FAILED"
    | "SERVER_NO_RANGE"
    | "SERVER_BAD_CONTENT"
    | "SERVER_UNAUTHORIZED"
    | "SERVER_CERT_PROBLEM"
    | "SERVER_FORBIDDEN"
    | "USER_CANCELED"
    | "USER_SHUTDOWN"
    | "CRASH"
State: "in_progress" | "interrupted" | "complete"

in_progress: The download is currently receiving data from the server. interrupted: An error broke the connection with the file host. complete: The download completed successfully.

These string constants will never change, however the set of States may change.

onChanged: WebExtEvent<(downloadDelta: _OnChangedDownloadDelta) => void>

When any of a DownloadItem's properties except bytesReceived changes, this event fires with the downloadId and an object containing the properties that changed.

onCreated: WebExtEvent<(downloadItem: DownloadItem) => void>

This event fires with the DownloadItem object when a download begins.

onErased: WebExtEvent<(downloadId: number) => void>

Fires with the downloadId when a download is erased from history.

The id of the DownloadItem that was erased.

  • Prompt the user to either accept or cancel a dangerous download. acceptDanger() does not automatically accept dangerous downloads.

    Parameters

    • downloadId: number

    Returns Promise<void>

    Unsupported on Firefox at this time.

  • Cancel a download. When callback is run, the download is cancelled, completed, interrupted or doesn't exist anymore.

    Parameters

    • downloadId: number

      The id of the download to cancel.

    Returns Promise<void>

  • Download a URL. If the URL uses the HTTP[S] protocol, then the request will include all cookies currently set for its hostname. If both filename and saveAs are specified, then the Save As dialog will be displayed, pre-populated with the specified filename. If the download started successfully, callback will be called with the new DownloadItem's downloadId. If there was an error starting the download, then callback will be called with downloadId=undefined and browser.extension.lastError will contain a descriptive string. The error strings are not guaranteed to remain backwards compatible between releases. You must not parse it.

    Parameters

    Returns Promise<number>

  • Initiate dragging the file to another application.

    Parameters

    • downloadId: number

    Returns void

    Unsupported on Firefox at this time.

  • Erase matching DownloadItems from history

    Parameters

    Returns Promise<number[]>

  • Retrieve an icon for the specified download. For new downloads, file icons are available after the onCreated event has been received. The image returned by this function while a download is in progress may be different from the image returned after the download is complete. Icon retrieval is done by querying the underlying operating system or toolkit depending on the platform. The icon that is returned will therefore depend on a number of factors including state of the download, platform, registered file types and visual theme. If a file icon cannot be determined, browser.extension.lastError will contain an error message.

    Parameters

    Returns Promise<string>

  • Open the downloaded file.

    Parameters

    • downloadId: number

    Returns Promise<void>

  • Pause the download. If the request was successful the download is in a paused state. Otherwise browser.extension.lastError contains an error message. The request will fail if the download is not active.

    Parameters

    • downloadId: number

      The id of the download to pause.

    Returns Promise<void>

  • Parameters

    • downloadId: number

    Returns Promise<void>

  • Resume a paused download. If the request was successful the download is in progress and unpaused. Otherwise browser.extension.lastError contains an error message. The request will fail if the download is not active.

    Parameters

    • downloadId: number

      The id of the download to resume.

    Returns Promise<void>

  • Find DownloadItems. Set query to the empty object to get all DownloadItems. To get a specific DownloadItem, set only the id field.

    Parameters

    Returns Promise<DownloadItem[]>

  • Parameters

    • enabled: boolean

    Returns void

    Unsupported on Firefox at this time.

  • Show the downloaded file in its folder in a file manager.

    Parameters

    • downloadId: number

    Returns Promise<boolean>

  • Returns void