Skip to main content
The Download class represents a file download initiated by the page. Downloads are created when a page triggers a file download, and you can handle them using the page.on('download') event.

Overview

Methods

url()

Get the download URL. Returns: string

suggestedFilename()

Get the suggested filename from the server. Returns: string This is the filename suggested by the Content-Disposition header or derived from the URL:

path()

Get the path to the downloaded file. Returns: Promise<string> Waits for the download to finish and returns the path to the downloaded file:

saveAs(path)

Save the download to a specific path.
string
required
Path where the file should be saved
Returns: Promise<void>

failure()

Get the failure reason if the download failed. Returns: Promise<string | null> Returns null if the download was successful:

createReadStream()

Get a readable stream for the downloaded file. Returns: Promise<Readable> Useful for processing large files without loading them entirely into memory:

cancel()

Cancel the download. Returns: Promise<void>

delete()

Delete the downloaded file. Returns: Promise<void>

page()

Get the page that initiated the download. Returns: Page

Examples

Basic Download

Check Download Success

Save with Suggested Filename

Stream Large File

Handle Multiple Downloads

Cancel Download

Verify Download Content

Wait for Download with Timeout

Best Practices

Wait Before Clicking

Set up the download listener before triggering the download:

Use Promise.all for Simultaneous Actions

Clean Up Downloads

Delete temporary downloads after testing:

Handle Download Failures

Common Issues

Download Not Triggered

Ensure the download actually starts:
Handle downloads from popups: