Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

How to Capture Blob Document Downloads With Playwright

Wait for Playwright’s download event before triggering a blob-backed file, save it before context shutdown, and debug cases where a blob URL does not emit an event.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

To capture a blob-backed file with Playwright, start waiting for the browser’s download event before clicking the control, then save the returned Download object. This works when the page’s action actually starts an attachment download; a URL beginning with blob: does not, by itself, guarantee that Playwright will emit that event.

Capture the download in JavaScript or TypeScript

Register the event waiter before triggering the action. If you click first, a fast download could begin before Playwright is listening.

As an Amazon Associate I earn from qualifying purchases.

const downloadPromise = page.waitForEvent('download');
await page.getByRole('button', { name: /download/i }).click();
const download = await downloadPromise;
await download.saveAs(`/tmp/${download.suggestedFilename()}`);

Replace the button locator and destination path for your application and test environment. The Playwright Download object provides the suggested filename and file operations; explicitly save the file to a stable location before the browser context closes. See Playwright’s download documentation.

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

Capture the download in Python

In Python, place the action inside page.expect_download(), then save the resulting download:

async with page.expect_download() as download_info:
    await page.get_by_role("button", name="Download").click()

download = await download_info.value
await download.save_as(f"/tmp/{download.suggested_filename}")

This example uses Playwright’s asynchronous Python API. With the synchronous API, use the same context-manager pattern without async and await. Keep the save path appropriate for your operating system and test runner.

Understand what a blob URL means

A blob: URL is an opaque browser-managed reference to data, often created from a Blob with URL.createObjectURL(). It is not a normal network URL to reconstruct or fetch by hand. A page can navigate to a blob URL or use it as a download link. The HTML anchor download attribute can mark blob: and data: URLs for downloading, but the attribute suggests a filename rather than guaranteeing identical handling in every browser. See MDN’s blob URL reference and MDN’s anchor download documentation.

Playwright documents its download event for attachment downloads. Its documentation does not establish that every blob creation, click, navigation, or browser setting produces that event. Test the exact app flow in the browsers you support; do not infer successful event capture merely from seeing a blob URL.

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

Blob URL lifetime matters

Applications create and release object URLs with URL.createObjectURL() and URL.revokeObjectURL(). Revoking too early can make the URL unusable before the browser consumes it. When debugging, check the application’s timing rather than immediately adding a second click or retry that could hide a lifecycle bug.

Choose the right event scope

For a known button on a known page, a Page-level waiter such as page.waitForEvent('download') or Python’s page.expect_download() is the clearest choice. If downloads may originate on multiple pages in the same browser context, a BrowserContext-level download event can observe them across pages; Playwright marks that context event as added in v1.60. See the Page download event and BrowserContext download event references.

For an unknown trigger, a Page listener can help identify where the event occurs:

page.on('download', async download => {
  await download.saveAs(`/tmp/${download.suggestedFilename()}`);
});

Event-handler work is asynchronous. Make sure the test waits for work started by the handler so it cannot outlive the test. Prefer an explicit waiter around a known action when possible; it makes the expected event and action easier to correlate.

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.

Persist and verify the file

Playwright stores downloads in a temporary location associated with the producing browser context. Those files are deleted when the context closes, so save the download before closing that context. The suggested filename is typically derived from the response’s Content-Disposition header or the HTML download attribute, and browser behavior can vary. If the filename matters, assert it instead of assuming it.

  • Check that the destination file exists after saving.
  • Assert the expected filename or extension when those are part of the test contract.
  • Check that the file is nonempty or has an expected size range if appropriate.
  • For PDFs or other structured documents, validate the contents or parseability rather than treating a successful event as proof the right document was captured.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot missing or incorrect downloads

Symptom Likely cause What to check
No download event arrives The waiter was installed after the action, the locator missed the real trigger, or the page navigated/opened a blob resource instead of starting an attachment download. Install the waiter before clicking; verify the actual control and inspect whether the page created an anchor with a blob URL and a download attribute or followed a different navigation path.
The download event occurs, but the file disappears The file remained in the browser context’s temporary download storage and the context closed. Call saveAs or save_as to copy it to a stable path before closing the context.
The saved file has an unexpected name The browser may choose a name based on Content-Disposition, the anchor’s download value, or browser-specific handling. Inspect the application’s link/response behavior and assert the filename your supported browser actually provides.
The blob link stops working The application may revoke its object URL before the browser has consumed it. Review when URL.revokeObjectURL() runs relative to the click and browser download action.
A listener starts saving but the test ends early Listener work may run separately from the main test flow. Await the save operation or use a waiter that returns the download directly, then save it in the test’s main flow.

Or skip the browser setup

If you need a screenshot of the page that presents the download control—not the blob file itself—ScreenshotNeo can return a website screenshot or PDF from one GET request. It does not capture a browser-managed blob download as a Playwright Download object.

For example, request a screenshot of the relevant page:

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

See the ScreenshotNeo API documentation for request options. Cookie banners, popups and chat widgets are removed before the shot; bot checks, blank pages and failed loads are never billed. An MCP server lets AI agents take screenshots, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

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

Frequently Asked Questions

Can Playwright download a file directly from a blob URL?

It can capture the download when the application’s browser interaction starts a download event. Seeing a blob URL alone does not prove that an event will fire; test the actual flow.

Should I save the download before closing the browser context?

Yes. Playwright’s context-owned temporary downloads are removed when the producing context closes, so copy needed files to a stable path first.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.