October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Modify and Continue an HTTP Request in Puppeteer

Use Puppeteer request interception to selectively change headers, method, post data, or URL, then continue each request safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Enable request interception before the request is made, then handle the page’s request event and call request.continue(overrides). Include only the fields you want to change—headers, method, post data, or URL—and make sure every intercepted request is resolved. Otherwise, it can hang.

Enable interception and continue a request

Register interception before navigation or the page action that triggers the request. This example adds a header to every intercepted request:

As an Amazon Associate I earn from qualifying purchases.

await page.setRequestInterception(true);

page.on('request', request => {
  if (request.isInterceptResolutionHandled()) return;

  const headers = {
    ...request.headers(),
    'x-example-header': 'example-value',
  };

  request.continue({ headers });
});

Interception pauses requests until a handler continues them, fulfills them with respond(), aborts them, or the browser serves them from cache. Puppeteer’s request interception guide warns that a request can hang if it is not explicitly resolved.

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

Change only the fields you need

The continue() overrides support headers, method, postData, and url. Pass only the properties you intend to change; leaving other fields out preserves their existing values.

  • headers: provide the header map you want sent. request.headers() returns lowercase header names. Copy it before adding or removing a value. To remove a header, the official example assigns it undefined in the copied map.
  • method: set the HTTP method for the continued request.
  • postData: set the request body data.
  • url: change the URL used for the continued request. This is not a redirect; a redirect is a separate response behavior.

See the HTTPRequest.continue() API reference for the override shape. The method reference was listed under Puppeteer 25.12.0; your installed package may differ, so consult the reference matching your version.

Apply overrides selectively

For a selective rule, inspect request properties such as URL, method, or resource type. Continue requests that do not match too: interception applies to the page’s requests, not only the one you want to edit.

await page.setRequestInterception(true);

page.on('request', request => {
  if (request.isInterceptResolutionHandled()) return;

  if (request.url().includes('/api/')) {
    request.continue({
      headers: {
        ...request.headers(),
        'x-example-header': 'example-value',
      },
    });
    return;
  }

  request.continue();
});

This listener assumes it is the only handler resolving interception. If other listeners or packages may handle the same request, use the resolution guard described below.

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.

Prevent duplicate resolution and handler races

A request should be resolved once. In legacy resolution behavior, if another listener has already called continue(), abort(), or respond(), trying to resolve it again can raise “Request is already handled!” Check isInterceptResolutionHandled() immediately before resolving.

When the handler performs asynchronous work, check again after the await. Another listener may resolve the request while your handler is waiting:

page.on('request', async request => {
  if (request.isInterceptResolutionHandled()) return;

  const shouldModify = await decideWhetherToModify(request.url());

  // Recheck after the await, immediately before resolving.
  if (request.isInterceptResolutionHandled()) return;

  if (shouldModify) {
    request.continue({
      headers: {
        ...request.headers(),
        'x-example-header': 'example-value',
      },
    });
  } else {
    request.continue();
  }
});

Replace decideWhetherToModify with your own asynchronous decision function; it is illustrative, not a Puppeteer API. In a synchronous handler, keep the handled check and the resolution call together without an intervening await. The official guide documents the guard and resolution conventions.

When multiple handlers use cooperative resolution

Cooperative interception lets handlers register resolutions with numeric priorities. All handlers must use a numeric priority for the cooperative convention to apply; a single resolution without a priority switches behavior to legacy immediate resolution. Higher priority wins. If priorities tie, the resolution order is abort, then respond, then continue.

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

A neutral continuation can use priority 0 or DEFAULT_INTERCEPT_RESOLUTION_PRIORITY. Use a custom priority only when you intend to influence which handler’s resolution wins. Do not mix cooperative and legacy calls if you expect all handlers to be considered.

Choose between continuing, responding, and aborting

  • Use continue(overrides) to send the request onward, optionally with changed fields.
  • Use respond(response) to fulfill the request from the interception handler instead of sending it onward in the usual way.
  • Use abort() to stop the request.

These methods resolve the interception. Choose one path for each request, taking care not to resolve it again from another handler.

Handle request bodies and response outcomes carefully

Post data may not be available through the older accessor

hasPostData() can be true even when postData() cannot provide the body—for example, when it is large or cannot be decoded. The current API reference marks postData() deprecated and directs users to fetchPostData() for fetching request data. Check the HTTPRequest API reference for the version installed in your project.

HTTP error statuses are not necessarily request failures

A completed HTTP response with status 404 or 503 is still a completed request; Puppeteer reports it through requestfinished. A transport or request failure is reported through requestfailed. A redirect finishes the original request and triggers a new request. Treat these events as different outcomes when diagnosing a page that did not load as expected.

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

Troubleshoot requests that hang or fail

  • The page waits indefinitely: check that interception was enabled before the request and that every branch of the listener resolves the request with continue(), respond(), or abort().
  • “Request is already handled!” appears: another handler may have resolved it. Check isInterceptResolutionHandled() just before resolution, and repeat the check after asynchronous work.
  • Your override seems to discard headers: construct the override from request.headers() and then add or remove the intended values. Header names returned by Puppeteer are lowercase.
  • The request body is missing: hasPostData() does not guarantee that postData() can return the content. Use the current fetchPostData() guidance in the API reference.
  • A 404 or 503 is reported: distinguish the HTTP response from a transport failure; an HTTP error status may still produce requestfinished.
  • The URL changed but no redirect occurred: changing the URL in continue() changes the URL of the continued request; it is not a redirect response.
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 to capture a page rather than control a browser request, ScreenshotNeo offers a screenshot API and MCP server. A single GET request returns an image or PDF. Its capture flow accepts cookie and consent banners and removes 60+ known consent platforms, newsletter popups, and chat widgets before the shot; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf.

Example cURL call (see the ScreenshotNeo documentation for API details):

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

Frequently Asked Questions

Does changing the URL in `continue()` create a redirect?

No. It changes the URL used for the continued request; a redirect is a separate response that finishes the original request and triggers another one.

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

Can I call `continue()` after another listener has resolved the request?

No. Check `isInterceptResolutionHandled()` immediately before resolving, and check again after any asynchronous work.

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
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.