Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Read Response Text in Puppeteer

Use Puppeteer’s awaited HTTPResponse.text() method for a UTF-8 response string, with safe patterns for navigation, clicks, and network events.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use await response.text() to read a Puppeteer response body as a UTF-8 string. For a page navigation, get the response from page.goto(); for a click-triggered navigation or an arbitrary network response, wait for the relevant response first.

Read the response from page.goto()

page.goto() resolves to an HTTPResponse when navigation produces a response. Call and await its text() method:

As an Amazon Associate I earn from qualifying purchases.

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

if (!response) {
  throw new Error('Navigation did not produce an HTTP response');
}

const bodyText = await response.text();
console.log(bodyText);

text() is asynchronous: it returns a promise, so await it before using the body. Puppeteer documents the result as a UTF-8 representation and says the method throws if the content is not a UTF-8 string. See the Puppeteer HTTPResponse API reference (version 25.12.0 shown on the reference as of October 3, 2026).

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

Check whether a response exists

Some navigations, including navigation to about:blank or to the same URL with only a hash change, can yield null. Check the value before calling text(), as in the example, to avoid trying to read from a missing response. The Page API documentation describes the navigation response behavior.

Read the response after a click or other action

If an action triggers navigation, start waiting for navigation and perform the action together. This avoids clicking first and only then starting to wait, which can miss a fast navigation:

const [response] = await Promise.all([
  page.waitForNavigation(),
  page.click('a.some-link'),
]);

const bodyText = response ? await response.text() : '';
console.log(bodyText);

Use a selector that matches the link or control in your page. The response can be null for navigation cases that do not produce a new HTTP response; handle that possibility before reading the body. This parallel-wait pattern is documented in the Puppeteer Page API.

Read matching responses from network activity

When you need an API response or another request that is not the main navigation, listen for the Page response event and filter by URL. The event provides an HTTPResponse. Because a body read can fail, keep it inside error handling:

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.
page.on('response', async response => {
  if (!response.url().includes('/api/items')) return;

  try {
    const bodyText = await response.text();
    console.log(response.status(), bodyText);
  } catch (error) {
    console.error('Could not read response body', response.url(), error);
  }
});

Filtering prevents the handler from trying to print every response on the page. The event’s role and response object are described in the PageEvent documentation.

Choose the right body method

Method Use it when Result or caveat
text() You want textual response content. Resolves to a UTF-8 string; throws if the content is not a UTF-8 string.
json() The body is JSON and you want to use it as data. Reads the response as JSON. See the HTTPResponse reference.
buffer() or content() You need body data as a Buffer rather than a string. Returns buffer data. Puppeteer notes that the browser may re-encode body data based on headers or heuristics. See the HTTPResponse reference.

Interpret the status separately from the body

A response can have an HTTP error status, such as 404 or 503, and still be a completed HTTP response. Check response.status() or response.ok() to determine HTTP success; do not treat a non-2xx status as automatically equivalent to a transport-level requestfailed event. When appropriate, you can still read the response body to inspect the server’s error details.

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

if (response) {
  console.log('HTTP status:', response.status());
  console.log('HTTP success:', response.ok());
  console.log('Body:', await response.text());
}

Puppeteer distinguishes HTTP error responses from failed requests in its API documentation; the PageEvent documentation covers the response event.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot response text reads

  • Cannot read properties of null: the navigation did not yield an HTTPResponse. Check for null before calling text(); hash-only and about:blank navigation are documented examples.
  • The body read throws: the response body may not be available, or its contents may not be a UTF-8 string. Catch the error when handling arbitrary network responses. If you need bytes, try buffer() or content() instead.
  • The click navigation is missed: register waitForNavigation() in the same Promise.all() as the click rather than after it.
  • The status is 404 or 503: that is an HTTP response status, not proof that the request failed at the transport level. Inspect status(), ok(), and, when available, the body.
  • The listener prints unrelated bodies: narrow the response.url() filter to the endpoint you want. Also catch body-read errors so one unavailable body does not become an unhandled rejection.

Or skip the browser setup

If your goal is a screenshot rather than reading response text, ScreenshotNeo provides a website screenshot API and MCP server. Its one-request API returns a screenshot or PDF, not the response body:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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. It removes cookie banners, newsletter popups and chat widgets before capture; bot checks, blank pages and failed loads are never billed. Its 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.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.