DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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 Wait for a Response in Puppeteer

Use page.waitForResponse() before the action that triggers a network call, then inspect the matching response and handle statuses, timeouts, and mismatches.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Puppeteer’s page.waitForResponse() when you need to wait for a matching network response, such as the result of an API call triggered by a click. Start the wait before the action, then await the returned HTTPResponse.

Wait for a response triggered by an action

Create the response-wait promise before clicking, submitting, or performing the action that sends the request. Then perform the action and await the promise. This ordering avoids missing a fast response before the wait is set up.

As an Amazon Associate I earn from qualifying purchases.

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

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

const body = await response.json();

page.waitForResponse() accepts a URL string or an asynchronous predicate and resolves to the matching response. The example uses a predicate so it can check both the URL and status. See the Puppeteer Page.waitForResponse() reference.

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

Match the response you actually need

A URL string is adequate when only one response can match it. Use a predicate when an endpoint is called repeatedly, query parameters vary, or the request method and response status matter.

const responsePromise = page.waitForResponse(async response => {
  if (response.url() !== 'https://example.com/api/search') return false;
  if (response.request().method() !== 'POST') return false;
  return response.status() === 200;
});

await page.locator('button.search').click();
const response = await responsePromise;

Receiving a response does not necessarily mean the operation succeeded. HTTP error responses such as 404 or 503 are still responses. If your script requires success, test the expected status or another application-specific condition and handle error responses explicitly.

Read the response body

Once the wait resolves, the result is an HTTPResponse. Read its body using the method that matches the response format—for example, json() for JSON or text() for text. If the body is not the expected format, inspect the response URL and status before parsing it.

Set a timeout and cancel when needed

The response wait defaults to a 30-second timeout. You can set a shorter or longer finite timeout in the options object. A timeout of 0 disables the timeout; the page-level default timeout can also change the default. A signal option supports cancellation. For routine automation, keep a finite timeout so a missing request does not leave the script waiting indefinitely.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const responsePromise = page.waitForResponse(
  response => response.url().includes('/api/data'),
  { timeout: 10_000 }
);

Choose a wait that matches the condition

What you need to wait for Puppeteer method What it gives you
A matching network response page.waitForResponse() The matching HTTPResponse
A matching outgoing request page.waitForRequest() The matching request, not its response
A selector to appear, become visible, or become hidden page.waitForSelector() An element handle, or a timeout if the requested condition is not met
A custom condition in the page context to become truthy page.waitForFunction() The function result
An element to be ready for an interaction Locators Locator actions wait for the element to be present and suitable for the action

Do not use a navigation wait as a substitute for an XHR or fetch response when the action does not navigate. Choose the API that represents the event or state your script needs to observe. See the Puppeteer page-interactions guide, waitForRequest() reference, waitForSelector() reference, and waitForFunction() reference.

Troubleshoot a wait that times out

  • The triggering action did not run: Confirm the click or submit completed and that the control was actionable. Puppeteer locators wait for an element to be present and suitable for the action.
  • The predicate does not match: Log observed response URLs, request methods, and statuses, then adjust the predicate to match the actual request. Check query parameters and redirects if relevant.
  • The wait starts too late: Create the waitForResponse() promise before the action that triggers the request.
  • The endpoint responds with an error status: The wait can still resolve. Inspect response.status() and handle the application error rather than treating receipt as success.
  • The response takes longer than the timeout: Set a finite timeout appropriate to the task and investigate why the request is slow. Avoid disabling the timeout unless an indefinite wait is intentional.
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 Puppeteer response handling, ScreenshotNeo offers a one-request screenshot API:

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 for the request options. Cookie banners are accepted and removed before capture, along with supported newsletter popups and chat widgets; those cleanup steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. An MCP server provides screenshot tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s 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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

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.