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 DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

How to Check Whether a Puppeteer Response Is Successful

Check Puppeteer HTTP responses with ok() for 2xx success or status() for an exact code, including safe navigation and waitForResponse examples.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a Puppeteer HTTPResponse, call response.ok() to check whether its HTTP status is in the 200–299 range. If your test requires one exact status or a custom rule, check response.status() instead. Guard against a missing response before calling either method.

Check the response returned by navigation

page.goto() returns an HTTPResponse that you can inspect. A completed navigation alone does not prove that the HTTP status was successful.

As an Amazon Associate I earn from qualifying purchases.

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

if (!response) {
  throw new Error('Navigation produced no HTTP response');
}

if (!response.ok()) {
  throw new Error(`HTTP ${response.status()} for ${response.url()}`);
}

ok() and status() are methods, so include parentheses. Puppeteer documents ok() as true for status codes from 200 through 299. A 404 or 500 response does not necessarily cause goto() to throw; inspect the returned response when HTTP status matters. Puppeteer: HTTPResponse.ok() · Puppeteer: Page.goto()

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

Choose between ok() and status()

  • response.ok() accepts any 2xx status. Use it when the test treats all 2xx responses as successful.
  • response.status() returns the numeric status. Compare it directly when the application requires a specific code, such as response.status() === 200.

Do not use status text as the success test. The numeric status or Puppeteer’s ok() method expresses the HTTP condition. Puppeteer: HTTPResponse.status()

Wait for a response triggered by an action

Start waiting before the click or other action that triggers the request. This avoids missing a response that arrives quickly. Match the response by URL or with a predicate:

const responsePromise = page.waitForResponse(
  response => response.url() === 'https://example.com/api/data'
);

await page.click('#load-data');

const response = await responsePromise;
if (!response.ok()) {
  throw new Error(`HTTP ${response.status()} for ${response.url()}`);
}

waitForResponse() resolves to the matching HTTPResponse. Its documented default timeout is 30 seconds; you can adjust the method’s timeout option or the page’s default timeout. Puppeteer: Page.waitForResponse()

Check application-level success separately

An HTTP 2xx status only establishes HTTP-level success. The response body may still describe an application error, and an API may require a narrower status rule. If the test depends on the content, inspect it as well as the status:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const response = await page.waitForResponse(
  response => response.url() === 'https://example.com/api/data'
);

if (!response.ok()) {
  throw new Error(`HTTP ${response.status()}`);
}

const data = await response.json();
if (!data.success) {
  throw new Error(`Application error: ${data.message ?? 'unspecified'}`);
}

Use a body assertion that matches your API’s actual response shape. Puppeteer’s response.json() throws if the body is not valid JSON; use response.text() when the response is not JSON or you need to assert raw content. The HTTPResponse API also exposes response URL, request, and headers for identifying or examining a response. Puppeteer: HTTPResponse

Common problems and fixes

  • Calling a method on null: page.goto() can return null for navigation to about:blank or to the same URL with a different hash. Check the result before calling ok(), status(), or url(). Page.goto() documentation
  • A 404 or 500 did not throw: a valid HTTP response can still have an unsuccessful status. Inspect the returned response with ok() or status().
  • waitForResponse() times out: ensure the wait is created before the triggering action and that the URL or predicate matches the response actually generated. The documented default timeout is 30 seconds; adjust it if the request legitimately takes longer.
  • response.json() fails: the body is not valid JSON. Check the response content type and use text() or an appropriate parser for the actual format.

Or skip the browser setup

If you only need a website screenshot rather than a browser response assertion, ScreenshotNeo offers a one-request screenshot API. Its cookie and consent handling removes known consent banners, newsletter popups, and chat widgets before capture; failed loads, blank pages, bot checks, and cache hits are not billed. It also provides an MCP server for AI agents.

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. ScreenshotNeo is not a substitute for testing HTTP response status in Puppeteer; it is an alternative when the task is capturing a page. The free plan includes 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for free.

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

Version note

Puppeteer documentation surfaced for versions 25.10.0 and 25.12.0. If your project uses an older release, check its installed version and matching API documentation when method availability or type definitions are in question.

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

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