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

To read a PDF returned by a network request in Puppeteer, wait for the matching HTTPResponse, then call await response.buffer(). Start page.waitForResponse() before the click or navigation that starts the download, and filter by status, URL, or content-type so you do not read an unrelated request.

Get the PDF response as a Node.js Buffer

This pattern captures a server-generated PDF and writes its original response bytes to disk:

import puppeteer from 'puppeteer';
import fs from 'node:fs/promises';

const browser = await puppeteer.launch();
const page = await browser.newPage();

const responsePromise = page.waitForResponse(async response => {
  const contentType = response.headers()['content-type'] || '';
  return response.status() === 200 &&
    contentType.includes('application/pdf');
});

await page.goto('https://example.com/reports');
await page.click('#download-pdf');

const response = await responsePromise;
const pdfBuffer = await response.buffer();
await fs.writeFile('document.pdf', pdfBuffer);

await browser.close();

HTTPResponse.buffer() returns a promise that resolves to a Node.js Buffer containing the response body. Because the promise is created before the click, the response cannot be missed if the browser starts the request immediately.

Wait before the action that triggers the download

The most common race condition is clicking first and registering a response listener afterward. Register the waiter, perform the action, and then await the response:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  1. Create responsePromise with page.waitForResponse().
  2. Navigate, click, submit, or run the script that causes the PDF request.
  3. Await the promise and call response.buffer().
  4. Persist or forward the bytes without converting them to text.

If the PDF endpoint is stable, URL matching can be more precise than content type alone:

const responsePromise = page.waitForResponse(response =>
  response.url().includes('/reports/') && response.status() === 200
);

await page.click('#download-pdf');
const response = await responsePromise;
const pdfBuffer = await response.buffer();

You can combine URL, status, and headers when several requests occur during one interaction. A successful HTTP status does not guarantee that the body is a PDF, so inspect the content-type whenever possible.

Choose a reliable response filter

Filter by content type

Use application/pdf when the server sets a correct MIME type and the page may use changing download URLs:

const pdfResponse = await page.waitForResponse(response => {
  const headers = response.headers();
  return response.status() === 200 &&
    (headers['content-type'] || '').toLowerCase().includes('application/pdf');
});

Filter by URL

Use a known path, query parameter, or host when the response header is unreliable:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const pdfResponsePromise = page.waitForResponse(response =>
  response.url().includes('/api/invoices/') && response.status() === 200
);

Filter by request method or other metadata

The response exposes url(), status(), headers(), and request(). For example, require a GET request to your PDF endpoint:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
const responsePromise = page.waitForResponse(response => {
  const request = response.request();
  return request.method() === 'GET' &&
    response.url().startsWith('https://example.com/export/') &&
    response.status() === 200;
});

Save, upload, or inspect the bytes

A Buffer can be written directly with the promises API:

await fs.writeFile('report.pdf', pdfBuffer);

For an upload, pass the buffer to your HTTP client as binary data. Do not call toString() unless you deliberately need diagnostic text; PDF bytes are not UTF-8 text. A quick sanity check is the PDF signature:

if (!pdfBuffer.subarray(0, 5).equals(Buffer.from('%PDF-'))) {
  throw new Error('The response was not a PDF document');
}

This check catches login pages, JSON error objects, and HTML bot-check pages that were returned with a misleading status.

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.

Handle responses that have no readable body

Do not call buffer() indiscriminately from a listener attached to every response. CORS preflight requests, 204 responses, and 304 responses may have no body, and a body can become unavailable before it is read.

page.on('response', async response => {
  if (response.request().method() === 'OPTIONS') return;
  if ([204, 304].includes(response.status())) return;

  const contentType = response.headers()['content-type'] || '';
  if (!contentType.includes('application/pdf')) return;

  try {
    const pdfBuffer = await response.buffer();
    await fs.writeFile('latest.pdf', pdfBuffer);
  } catch (error) {
    console.error('PDF body unavailable:', response.url(), error);
  }
});

Use waitForResponse() when one action should produce one PDF. A broad page.on('response') listener is useful for observing many possible downloads, but it must include guards and error handling.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Network PDF versus a PDF generated by Puppeteer

A downloaded PDF and a rendered PDF are separate workflows.

Use response.buffer() for a server-produced file

Choose the network response when the server already creates the final PDF. You preserve the server’s document, authentication context, and response bytes. This is the correct method for an export or download button whose request returns application/pdf.

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

Use page.pdf() to print the current page

Choose page.pdf() when Puppeteer should render the current DOM into a new document. Puppeteer uses the print CSS media type and returns Uint8Array bytes, which you can adapt to a Node buffer:

const pdfBytes = await page.pdf({
  format: 'A4',
  printBackground: true
});
const pdfBuffer = Buffer.from(pdfBytes);
await fs.writeFile('rendered-page.pdf', pdfBuffer);

This workflow does not capture a PDF response from the network. It prints what the browser has rendered, so page state, fonts, images, print styles, margins, and timing affect the result.

Authentication and request timing

When the PDF requires a login, establish the session before creating the waiter. Puppeteer then sends the request with the page’s cookies and authentication state. If the export is generated only after JavaScript finishes, wait for the UI element or application state that indicates it is ready, but still create the response waiter before the final click.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

For requests triggered by navigation, start waiting before page.goto():

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.
const responsePromise = page.waitForResponse(response =>
  response.url().includes('/download/report.pdf') &&
  response.status() === 200
);
await page.goto('https://example.com/start-download');
const response = await responsePromise;
const pdfBuffer = await response.buffer();

Performance, reliability, and byte fidelity

  • Use a narrow predicate. Pages can issue dozens of requests for scripts, analytics, images, and preflights. A URL plus status or MIME check avoids resolving the wrong response.
  • Set an appropriate timeout. Keep the wait long enough for the export service to finish, and catch timeout errors so the job reports which action failed.
  • Keep data binary. Write the buffer directly or pass it as a binary request body. Base64 or text conversions increase memory use and can corrupt bytes.
  • Validate the result. Check the first bytes for %PDF- and, when practical, confirm a nonzero size before publishing the file.
  • Account for browser re-encoding. Puppeteer documents that a response buffer might be re-encoded by the browser according to HTTP headers or other heuristics. If exact byte fidelity matters, verify the endpoint’s headers and inspect the resulting signature and file with your own PDF tooling.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

waitForResponse() times out

  • The waiter was registered after the click. Move it before the action.
  • The predicate is too strict. Log response.url(), status(), and headers, then adjust the URL or MIME test.
  • The action opens a new page or download flow instead of producing a response on the current page. Observe the relevant page or target.

The buffer contains HTML or JSON

The server may have redirected to a login page, returned an application error, or shown a bot check with status 200. Require application/pdf, check the final URL, and verify the %PDF- signature before saving.

response.buffer() rejects

The response may be bodyless, already unavailable, or an unsuitable preflight/304 response. Exclude those statuses and methods, and wrap the read in try/catch as shown above.

The saved PDF is corrupted

Do not decode the buffer as UTF-8 or write a string representation. Write the buffer directly, inspect response headers, and account for possible browser/header-driven re-encoding.

The file is empty

Confirm that the matched response is the actual export rather than an intermediate request. Log its URL, status, content type, and pdfBuffer.length; then tighten the predicate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Or skip the browser setup

For URL-based screenshot or PDF capture, ScreenshotNeo provides a single HTTP request instead of maintaining Puppeteer code. Its service accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.

cURL:

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}`);

See the ScreenshotNeo documentation for request options. Its MCP server includes take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.

FAQ

Does HTTPResponse.buffer() download the file automatically?

No. It reads the body of a response Puppeteer has observed. You must write or forward the returned buffer yourself.

Can I use the same buffer with an object-storage SDK?

Yes. Pass the Node.js Buffer as the binary body using the SDK’s upload method, while preserving a PDF content type where the storage service supports metadata.

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

Should I wait for a browser download event instead?

Use response waiting when the PDF is an HTTP response you need to inspect. Use download-specific handling when the site only exposes a browser download and does not give you a convenient response to select.

Frequently Asked Questions

What is the simplest Puppeteer expression for a PDF body?

After selecting the correct response, use const pdfBuffer = await response.buffer();.

Why does page.pdf() return a different type?

page.pdf() generates a new document and returns Uint8Array bytes; wrap them with Buffer.from() when a Node.js Buffer is required.

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.

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