PlaywrightEx.Download (PlaywrightEx v0.13.0)

Copy Markdown View Source

A browser download's metadata and underlying artifact.

Obtain a handle with PlaywrightEx.Page.await_download/1 or from_event/2. The browser provides suggested_filename and url when downloading starts.

save_as/3 waits for completion and preserves the source artifact. Closing the browser context deletes the source; saved copies belong to the caller.

Summary

Functions

Explicitly deletes the source download artifact. Saved copies are unaffected.

Builds a download handle from a raw :download event without reading its file.

Saves the completed download to path, preserving its source artifact.

Types

event_opt()

@type event_opt() :: {:connection, GenServer.name()}

opt()

@type opt() :: {:timeout, timeout()}

t()

@type t() :: %PlaywrightEx.Download{
  artifact_guid: PlaywrightEx.guid(),
  connection: GenServer.name(),
  page_id: PlaywrightEx.guid(),
  suggested_filename: String.t(),
  url: String.t()
}

Functions

delete(download, opts \\ [])

@spec delete(t(), [opt() | PlaywrightEx.unknown_opt()]) ::
  {:ok, any()} | {:error, any()}

Explicitly deletes the source download artifact. Saved copies are unaffected.

Options

  • :timeout (timeout/0) - Required. Operation timeout in milliseconds. 0 means no waiting; :infinity disables the timeout.

from_event(event, opts \\ [])

@spec from_event(map(), [event_opt()]) :: t()

Builds a download handle from a raw :download event without reading its file.

Pass the recorder's connection when using a non-default connection.

Options

  • :connection (term/0) - The Connection process name. Defaults to PlaywrightEx.Supervisor.Connection. The default value is PlaywrightEx.Supervisor.Connection.

save_as(download, path, opts \\ [])

@spec save_as(t(), Path.t(), [opt() | PlaywrightEx.unknown_opt()]) ::
  :ok | {:error, any()}

Saves the completed download to path, preserving its source artifact.

Uses the handle's connection and applies the timeout to the whole transfer. The caller owns the saved file. See PlaywrightEx.Artifact.save_as/3 for details.

Options

  • :timeout (timeout/0) - Required. Operation timeout in milliseconds. 0 means no waiting; :infinity disables the timeout.