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.
Implementations§
Source§impl Download
impl Download
Sourcepub fn from_artifact(
artifact: Arc<dyn ChannelOwner>,
url: String,
suggested_filename: String,
) -> Self
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)
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
Returns the download URL.
See: https://playwright.dev/docs/api/class-download#download-url
Sourcepub fn suggested_filename(&self) -> &str
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
Sourcepub async fn path(&self) -> Result<Option<PathBuf>>
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
Sourcepub async fn save_as(&self, path: impl AsRef<Path>) -> Result<()>
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
Sourcepub async fn cancel(&self) -> Result<()>
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
Sourcepub async fn delete(&self) -> Result<()>
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