Download

Struct Download 

Source
pub struct Download { /* private fields */ }
Expand description

Download represents a file download triggered by the page.

Downloads are dispatched via the page.on(‘download’) event. The download will be automatically deleted when the browser context closes.

NOTE: Unlike other protocol objects, Download is a wrapper around the Artifact protocol object. The URL and suggested_filename come from the download event params, while the actual file operations are delegated to the underlying Artifact.

See: https://playwright.dev/docs/api/class-download

Implementations§

Source§

impl Download

Source

pub fn from_artifact( artifact: Arc<dyn ChannelOwner>, url: String, suggested_filename: String, ) -> Self

Creates a new Download from an Artifact and event params

This is NOT created via the object factory, but rather constructed directly from the download event params which contain {url, suggestedFilename, artifact}.

§Arguments
  • artifact - The Artifact protocol object (from event params)
  • url - Download URL (from event params)
  • suggested_filename - Suggested filename (from event params)
Source

pub fn url(&self) -> &str

Source

pub fn suggested_filename(&self) -> &str

Returns the suggested filename for the download.

This is typically the server-suggested filename from the Content-Disposition header or the HTML download attribute.

See: https://playwright.dev/docs/api/class-download#download-suggested-filename

Source

pub async fn path(&self) -> Result<Option<PathBuf>>

Returns the path to the downloaded file after it completes.

This method waits for the download to finish if necessary. Returns an error if the download fails or is canceled.

See: https://playwright.dev/docs/api/class-download#download-path

Source

pub async fn save_as(&self, path: impl AsRef<Path>) -> Result<()>

Saves the download to the specified path.

This method can be safely called while the download is still in progress. The file will be copied to the specified location after the download completes.

§Example
download.save_as("/path/to/save/file.pdf").await?;

See: https://playwright.dev/docs/api/class-download#download-save-as

Source

pub async fn cancel(&self) -> Result<()>

Cancels the download.

After calling this method, failure() will return an error message.

See: https://playwright.dev/docs/api/class-download#download-cancel

Source

pub async fn delete(&self) -> Result<()>

Deletes the downloaded file.

The download must be finished before calling this method.

See: https://playwright.dev/docs/api/class-download#download-delete

Source

pub async fn failure(&self) -> Result<Option<String>>

Returns the download error message if it failed, otherwise None.

See: https://playwright.dev/docs/api/class-download#download-failure

Trait Implementations§

Source§

impl Clone for Download

Source§

fn clone(&self) -> Download

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Download

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more