The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Use the asynchronous body-reading method that matches the response: await response.text() for UTF-8 text, await response.json() for JSON, or await response.content() / await response.buffer() for bytes. Puppeteer responses do not expose a synchronous response.body property. First make sure you captured the response you want, then inspect its status and read its body.
Read the response from a page navigation
page.goto() resolves to the main resource’s HTTPResponse after redirects, or null in some special cases, including navigation to about:blank or a same-URL hash change. Check for a response before reading it:
const response = await page.goto('https://example.com/api/data');
if (!response) {
throw new Error('Navigation did not produce a main resource response');
}
console.log('status:', response.status());
console.log('URL:', response.url());
console.log('body:', await response.text());
The body methods are asynchronous, so use await (or return their promises). A 404 or 500 does not necessarily make page.goto() throw: the server may have returned a normal HTTP response carrying an error status and body. Check the status separately before treating that body as successful data.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsChoose the right body-reading method
| What you need | Method | Result | What can fail |
|---|---|---|---|
| Readable textual body | await response.text() |
UTF-8 string | Throws if the content is not valid UTF-8. |
| JSON data | await response.json() |
Parsed JavaScript value | Throws if the body cannot be parsed as JSON. |
| Raw or binary data | await response.content() |
Uint8Array |
The browser may re-encode bytes based on headers or heuristics. |
| Bytes for Node.js Buffer operations | await response.buffer() |
Buffer |
Returned bytes may reflect browser re-encoding, not an assumed wire-level byte sequence. |
The official HTTPResponse reference currently identifies Puppeteer version 25.12.0 and describes content() as resolving to a Uint8Array; use buffer() when your Node.js code needs Buffer-specific operations. See the Puppeteer HTTPResponse API.
#1 Best Overall
Read JSON and handle malformed payloads
const response = await page.goto('https://example.com/api/data');
if (!response) throw new Error('No main resource response');
try {
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Response body was not valid JSON:', error);
console.error('Raw body:', await response.text());
}
A JSON content-type header does not guarantee that the body is valid JSON. The catch block’s text read can help diagnose an unexpected response, such as an HTML error page returned by an API endpoint.
Capture a response triggered after navigation
If page JavaScript or an interaction makes the request, page.goto() is not the response you need. Register a waiter before triggering the action so the response is not missed. Make the predicate specific enough to avoid matching unrelated scripts, images, or other traffic.
Rank #2
const responsePromise = page.waitForResponse(response =>
response.url().includes('/api/data')
);
await page.click('button.load-data');
const response = await responsePromise;
console.log('status:', response.status());
const data = await response.json();
console.log(data);
You can also listen for response events and filter them. Catch body-reading errors in the listener so an invalid payload does not become an unhandled rejection:
Free tools Windows power users keep installed
One-click scans. No signup required.
page.on('response', async response => {
if (!response.url().includes('/api/data')) return;
try {
console.log('status:', response.status());
console.log(await response.text());
} catch (error) {
console.error('Could not read response body:', error);
}
});
The Page API documents waitForResponse(); response events are also documented in Puppeteer’s PageEvent reference.
Check status and response metadata
Receiving an HTTPResponse and receiving a successful HTTP status are different outcomes. Use status() for the numeric status or ok() to check whether the status is in the 200–299 range. Other useful metadata methods include headers(), url(), and request().
const response = await page.goto('https://example.com/api/data');
if (!response) throw new Error('No response');
if (!response.ok()) {
console.error('HTTP status:', response.status());
console.error('Response body:', await response.text());
} else {
console.log(await response.json());
}
Puppeteer distinguishes HTTP error responses from network-level request failures: a 404 or 503 can still complete with requestfinished, rather than requestfailed. A timeout or similar transport failure is a different case. See the PageEvent documentation.
Rank #4
Troubleshoot common response-reading problems
responseis null afterpage.goto(): some navigations, includingabout:blankand a same-URL hash change, have no main-resource response. Handlenullbefore calling a body method. Thepage.goto()reference documents this behavior.- You read the wrong body:
page.goto()gives the main navigation response, not a later API call. For interaction-triggered traffic, startwaitForResponse()before the click and filter by endpoint, and optionally request method. json()throws: the body may be malformed JSON or not JSON at all. Read it withtext()to inspect the payload, and check status and headers before assuming the endpoint succeeded.text()throws: the body may not be valid UTF-8. Usecontent()orbuffer()when the response is binary or its encoding needs inspection.- A 404 or 500 seems like a Puppeteer failure: it is still an HTTP response if the server returned it. Inspect
status()and the body; distinguish it from a request failure such as a timeout. - Bytes differ from an expected network capture: Puppeteer notes that the browser may re-encode content according to headers or heuristics. Do not assume
content()orbuffer()is always the exact wire representation.
Or skip the browser setup
If you need a screenshot rather than the response body, ScreenshotNeo returns an image or PDF from one GET request. See the API documentation.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchQuick Recap
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo removes cookie banners, popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000.
Sign up for ScreenshotNeo free.
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.

