DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
FREEDOM251

Freedom251 › Blog › HTTPResponse

How to Read the Content of a Puppeteer Response

By Freedom251 Team · · 4 min read

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

Read a Puppeteer response body with an asynchronous method on its HTTPResponse object: use await response.text() for UTF-8 text, await response.json() for parsed JSON, or await response.content() / await response.buffer() for bytes. First make sure you captured the response you want, then check its status separately from reading its body.

Read the body using the method that matches its format

Puppeteer does not expose the body as a synchronous response.body property. Its body-reading methods return promises, so await the method before using the result.

As an Amazon Associate I earn from qualifying purchases.

What you need Method Result Important caveat
Readable text await response.text() UTF-8 string Throws if the body is not valid UTF-8.
JSON data await response.json() Parsed JavaScript value Throws if the body cannot be parsed as JSON.
Body bytes await response.content() Uint8Array The browser may re-encode bytes based on headers or heuristics.
Node.js Buffer operations await response.buffer() Buffer Returned bytes may reflect browser re-encoding.

The official Puppeteer HTTPResponse reference is for version 25.12.0 and documents content() as resolving to Uint8Array; use HTTPResponse API for the current API details.

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

Read a navigation response

page.goto() resolves to the main resource’s response, or null in cases such as navigating to about:blank or changing only the URL hash. Redirects lead to the final response. In headless shell, an HTTP status such as 404 or 500 does not by itself make navigation throw, so inspect the returned response.

const response = await page.goto('https://example.com/api/data');

if (!response) {
  throw new Error('No main resource response');
}

console.log('status:', response.status());
console.log('URL:', response.url());
console.log(await response.text());

For JSON, replace the final line with console.log(await response.json()). page.goto() is for the navigation’s main resource; it is not a general way to retrieve every request the page makes. See the Page.goto() API for its documented return behavior.

Capture a later request triggered by the page

If a click or page script triggers the API request, start waiting for the response before performing the action. Filter on a distinctive URL or other response property so you do not accidentally read a script, image, or unrelated request.

const responsePromise = page.waitForResponse(response =>
  response.url().includes('/api/data')
);

await page.click('button.load-data');
const response = await responsePromise;
console.log(await response.json());

For more control, include the request method or other relevant details in the predicate. The waitForResponse() API documents this response-waiting approach.

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.

You can also listen for responses and filter them. Because the event listener below is asynchronous, errors from reading or parsing a body should be handled if they must not become unhandled rejections.

page.on('response', async response => {
  if (response.url().includes('/api/data')) {
    try {
      console.log(await response.text());
    } catch (error) {
      console.error('Could not read response body:', error);
    }
  }
});

The response event and its relationship to request completion are described in the PageEvent API.

Check status separately from the response body

A response object means Puppeteer received an HTTP response; it does not mean the server returned a successful status. Use response.ok() for a boolean indicating a 2xx status, or inspect response.status() for the exact code. You can still read an error page or error payload from a 404 or 503 response.

const response = await page.goto('https://example.com/api/data');
if (!response) throw new Error('No main resource response');

if (!response.ok()) {
  console.error('HTTP status:', response.status());
  console.error('Body:', await response.text());
} else {
  console.log(await response.json());
}

Puppeteer’s PageEvent documentation explains that HTTP error responses such as 404 or 503 complete with requestfinished, not requestfailed. A request failure instead represents a failure such as a timeout. Check the status and body for HTTP errors; use request-failure handling for network-level problems.

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.

Troubleshoot body-reading problems

  • The response is missing: page.goto() can return null for documented special navigations. Check for null before calling a body method.
  • You captured the wrong response: Make the waitForResponse() predicate more specific, for example by matching the endpoint and, if useful, the request method.
  • json() throws: The body may be malformed JSON or not JSON at all. Read it with text() while diagnosing, then parse or handle the payload appropriately.
  • text() throws: The body may not be valid UTF-8. Use content() or buffer() when you need byte-oriented handling.
  • You expected a network failure but received a response: An HTTP 4xx or 5xx status is still an HTTP response. Inspect status() and the body rather than relying on requestfailed.
  • Bytes differ from what you expected on the wire: Puppeteer documents that the browser may re-encode content based on headers or heuristics. Do not assume the returned body bytes are always an exact copy of the original wire representation.
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 a website screenshot rather than inspecting an API payload, ScreenshotNeo returns a screenshot or PDF from one GET request. Its screenshot capture accepts cookie and consent banners like a visitor, then removes 60+ known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. It also provides an MCP server with screenshot, page-info, and PDF tools for AI agents.

Example request using cURL (see 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

The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for 1,000 free screenshots a month, with no card 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.

HTTPResponseJavaScriptNode.jsPuppeteerweb scraping

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.

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.