Index

Functions

downloadUrl

  • downloadUrl(url: string, saveAs: boolean): Promise<void>
  • Download a given URL to disk

    Normal URLs are downloaded normally. Data URLs are handled more carefully as it's not allowed in WebExt land to just call downloads.download() on them

    Parameters

    • url: string

      the URL to download

    • saveAs: boolean

      prompt user for a filename

    Returns Promise<void>

downloadUrlAs

  • downloadUrlAs(url: string, saveAs: string): Promise<unknown>
  • Dowload a given URL to disk

    This behaves mostly like downloadUrl, except that this function will use the native messenger in order to move the file to saveAs.

    Note: this requires a native messenger >=0.1.9. Make sure to nativegate for this.

    Parameters

    • url: string

      the URL to download

    • saveAs: string

      If beginning with a slash, this is the absolute path the document should be moved to. If the first character of the string is a tilda, it will be expanded to an absolute path to the user's home directory. If saveAs begins with any other character, it will be considered a path relative to where the native messenger binary is located (e.g. "$HOME/.local/share/tridactyl" on linux). If saveAs points to a directory, the name of the document will be inferred from the URL and the document will be placed inside the directory. If saveAs points to an already existing file, the document will be saved in the downloads directory but wont be moved to where it should be ; an error will be thrown. If any of the directories referred to in saveAs do not exist, the file will be kept in the downloads directory but won't be moved to where it should be.

    Returns Promise<unknown>

objectUrlFromDataUrl

  • objectUrlFromDataUrl(dataUrl: URL): string
  • Construct an object URL string from a given data URL

    This is needed because feeding a data URL directly to downloads.download() causes "Error: Access denied for URL"

    Parameters

    • dataUrl: URL

      the URL to make an object URL from

    Returns string

    object URL that can be fed to the downloads API