What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wrap the click (or other download-triggering action) in page.expect_download(), then call download.save_as() before closing the browser context. The context owns the temporary download, so saving it first is what makes the file persist at a path your Python program controls.

Install Playwright and its browsers

Install the Python package and browser binaries in the environment that will run the script:

python -m pip install playwright
playwright install

The second command downloads the browser engines Playwright launches. In restricted networks, the installer supports proxy settings, a custom download host, and a configurable connection timeout. Make sure the account running your script can write to the destination directory.

The reliable download pattern

Register the download wait before performing the action that starts the download. A fast response can otherwise arrive before your code begins waiting. The context manager returns a Download object when the browser reports the event.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty
with page.expect_download() as download_info:
    page.get_by_text("Download file").click()
download = download_info.value

Use save_as() to copy the completed or in-progress download to your chosen path. It waits as necessary and is safe to call while the transfer is still running.

Complete synchronous Python example

This version creates the destination directory, preserves the browser-suggested name, saves the file, and only then closes the context:

from pathlib import Path
from playwright.sync_api import sync_playwright

output_dir = Path("downloads")
output_dir.mkdir(parents=True, exist_ok=True)

with sync_playwright() as playwright:
    browser = playwright.chromium.launch()
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://example.com")

    with page.expect_download() as download_info:
        page.get_by_text("Download file").click()

    download = download_info.value
    destination = output_dir / download.suggested_filename
    download.save_as(destination)

    context.close()
    browser.close()

Replace the example URL and locator with the page and control in your workflow. The locator can be a role, label, text locator, CSS selector, or another locator appropriate for the page. Creating the directory is your responsibility; save_as() does not create missing parent directories.

Asynchronous Python version

In an async application, use the async API and await both the browser operations and download methods:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import asyncio
from pathlib import Path
from playwright.async_api import async_playwright

async def main():
    output_dir = Path("downloads")
    output_dir.mkdir(parents=True, exist_ok=True)

    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch()
        context = await browser.new_context()
        page = await context.new_page()
        await page.goto("https://example.com")

        async with page.expect_download() as download_info:
            await page.get_by_text("Download file").click()

        download = await download_info.value
        destination = output_dir / download.suggested_filename
        await download.save_as(destination)

        await context.close()
        await browser.close()

asyncio.run(main())

Do not mix synchronous objects with the async API. The control flow is the same: create a context, begin waiting, trigger the download, save it, and close the context.

Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]

Choose the filename and destination

Use the browser-suggested name

download.suggested_filename is usually derived from the response’s Content-Disposition header or the HTML download attribute. It is a suggestion, not a guarantee that every browser will calculate the same name. This is the most useful choice when the server supplies meaningful names:

destination = Path("downloads") / download.suggested_filename
download.save_as(destination)

Use a fixed name

For a pipeline that always expects one artifact, select your own filename instead of relying on server metadata:

destination = Path("downloads/report.pdf")
download.save_as(destination)

Validate or normalize a server-provided name before using it in a multi-tenant or untrusted workflow. A fixed directory and an application-defined filename make the storage policy explicit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inspect the temporary path

After a successful download, download.path() returns Playwright’s temporary file path. The internal name is a random GUID, so use suggested_filename when you need a human-readable name. For normal local runs, save_as() is preferable because it copies directly to your controlled destination.

Keep the download alive long enough to save it

Downloads belong to the browser context that created them. Playwright removes temporary download files when that context closes. Always call save_as() (or otherwise copy the data) before context.close(). Closing the page or context while the event is still pending can also prevent the expected download from arriving.

Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers

Contexts accept downloads by default. If you need browser artifacts to remain after the browser closes, launch with an artifacts_dir; without that option Playwright uses a temporary directory and cleans it up on browser close.

Timeouts, predicates, and download status

Allow enough time

page.expect_download() has a documented default timeout of 30,000 milliseconds. Override it when the site takes longer to start a transfer:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
with page.expect_download(timeout=90_000) as download_info:
    page.get_by_role("button", name="Export").click()

The timeout covers waiting for the download event, not an arbitrary amount of time after your script has already moved on. Keep the page and context open until the event and save operation finish.

Filter when several controls can download

The wait accepts an optional predicate. For example, select the event whose suggested name ends in .csv:

with page.expect_download(
    predicate=lambda item: item.suggested_filename.endswith(".csv")
) as download_info:
    page.get_by_role("button", name="Export").click()

download = download_info.value
download.save_as("downloads/data.csv")

Use a predicate only when it distinguishes the intended event; otherwise a broad wait is simpler and less likely to reject a valid filename.

Rank #4
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.

Check failures explicitly

After the event, download.failure() waits for completion and returns an error when the transfer failed. An active transfer can be stopped with download.cancel(), and an already downloaded temporary file can be removed with download.delete():

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
error = download.failure()
if error:
    raise RuntimeError(f"Download failed: {error}")

download.save_as("downloads/result.bin")

Common problems and fixes

Symptom Likely cause Fix
expect_download times out The action did not initiate a browser download, the locator targeted the wrong element, or the site took longer than 30 seconds. Verify the locator, keep the wait around the triggering action, increase timeout, and check whether the click opens a viewer instead of an attachment.
The file disappears after the script exits The temporary file was never copied before its browser context closed. Call save_as() before closing the context and use a destination outside Playwright’s temporary directory.
The destination path raises a file-not-found error The parent directory does not exist. Create it first with Path(path).mkdir(parents=True, exist_ok=True).
The saved name is unexpected The browser derived a different suggestion from Content-Disposition or the download attribute. Log download.suggested_filename, or choose a fixed application-defined filename.
The download reports an error The server canceled the response, authentication expired, or the connection failed. Call download.failure(), preserve the error text in your logs, and retry only after addressing the server or session cause.
The browser cannot start The Python package is installed but its browser binaries are missing, or the runtime cannot reach the download host. Run playwright install in the same environment and configure the documented proxy, host, or timeout settings for your network.
The page closes before the event A redirect, test teardown, or exception closed the page or context while Playwright was waiting. Keep the page and context alive through the wait and save operation; move cleanup into a final block that runs afterward.

Production and test-suite considerations

  • Control lifetimes explicitly. Create a browser context and page yourself when a job, test, or worker needs a precise ownership boundary.
  • Use deterministic destinations. Separate each job’s output directory or filename so concurrent runs do not overwrite one another.
  • Record status. Save the suggested filename and the result of failure() in logs. A successful event does not replace application-level validation of file type or size.
  • Save before cleanup. Put context and browser closure after the copy, even when using context managers, so a temporary download is not deleted prematurely.
  • Account for slow responses. Set a timeout that matches the site and network, but keep it finite so a stuck transfer does not hold a worker forever.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is simply a clean image or PDF of a URL rather than a browser-driven attachment, ScreenshotNeo provides a GET endpoint. It accepts consent banners before capture and removes 60+ known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server also lets Claude, Cursor, or another MCP client call take_screenshot, get_page_info, and capture_pdf.

cURL (the API details are in the ScreenshotNeo documentation):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' }); const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots, and every feature is included on every plan. Sign up for the free ScreenshotNeo plan.

FAQ

Can I call download.path() over a remote connection?

No. The API reference says download.path() throws when the browser is connected remotely. Use save_as() to copy the file to a path available to your workflow instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where does Playwright cache its browser binaries?

The setup guide documents operating-system-specific cache locations. The default installer uses Microsoft’s CDN; environments that cannot reach it need the documented proxy or custom-host configuration.

Best Value
Sale
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.

What happens if I need to stop a transfer?

Call download.cancel() while it is active. Afterward, use download.failure() if you need the resulting error state for logging or control flow.

Frequently Asked Questions

Can I call download.path() over a remote connection?

No. The API reference says download.path() throws when the browser is connected remotely. Use save_as() to copy the file to a path available to your workflow instead.

Where does Playwright cache its browser binaries?

The setup guide documents operating-system-specific cache locations. The default installer uses Microsoft’s CDN; environments that cannot reach it need the documented proxy or custom-host configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What happens if I need to stop a transfer?

Call download.cancel() while it is active. Afterward, use download.failure() if you need the resulting error state for logging or control flow.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.