October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Abort an HTTP Request in Puppeteer

Enable request interception before navigation, then abort matching Puppeteer requests and resolve every other request by continuing it.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To abort selected requests in Puppeteer, enable request interception before navigation, then call request.abort() for matching requests and request.continue() for the rest. Every intercepted request must be resolved; otherwise it stalls.

Abort a request with Puppeteer

This example blocks image requests whose URLs end in .png or .jpg. Enable interception before navigating so the handler can resolve requests as the page loads:

As an Amazon Associate I earn from qualifying purchases.

await page.setRequestInterception(true);

page.on('request', request => {
  if (request.url().endsWith('.png') || request.url().endsWith('.jpg')) {
    request.abort();
  } else {
    request.continue();
  }
});

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

The handler uses Puppeteer’s legacy immediate-resolution behavior: each matching request is aborted, and every other request is continued. Replace the suffix test with a predicate that matches only the traffic you intend to block.

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

Choose what to match

An HTTPRequest exposes properties including its URL, method, resource type, and whether it is a navigation request. Use the narrowest relevant condition; blocking too broadly can prevent the page from loading correctly.

Match by URL or hostname

For example, use request.url() to check for a particular path or hostname. A hostname check is generally safer than a broad substring test, which can unintentionally match unrelated URLs.

Match by resource type or method

Use request.resourceType() when the rule should apply to a category of traffic, or request.method() when it should apply to a particular HTTP method. Combine conditions if needed so that only the intended requests are affected.

Resolve every intercepted request

After page.setRequestInterception(true), intercepted requests stall until they are continued, aborted, responded to, or completed using the browser cache. Ensure every branch in your handler resolves the request. Puppeteer documents abort(), continue(), and respond() as the request-resolution operations; use respond() when the page should receive a supplied response instead of making the request normally.

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

request.abort() requires interception to be enabled and throws immediately if it is not. Do not enable interception after navigation if the requests you need to stop may already have started.

Handle multiple request listeners safely

If another listener or a package may also resolve requests, check whether the request has already been handled before acting. Keep the check and the resolution call together without an asynchronous gap:

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

  if (request.url().includes('/blocked-path')) {
    request.abort();
  } else {
    request.continue();
  }
});

This synchronous pattern matters because another listener can handle a request while an asynchronous handler is waiting. If a handler must do asynchronous work before deciding, check again immediately before resolving the request.

Cooperative interception priorities

Puppeteer also supports cooperative interception when multiple handlers need to contribute decisions. In that mode, every resolution must supply a numeric priority; the highest priority wins, and equal priorities are resolved in this order: abort, respond, continue. A handler that resolves without a priority activates legacy immediate resolution, so retain the already-handled check even when using priorities.

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.

Tell an aborted request from an HTTP error

An aborted request triggers requestfailed. An HTTP response such as 404 or 503 is still a response and completes with requestfinished. That distinction helps identify whether your interception rule stopped the request or the server returned an error.

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common problems

  • abort() throws: Confirm that await page.setRequestInterception(true) ran before the handler tries to abort.
  • The page hangs or requests never finish: Check every handler branch. With interception enabled, a request must be resolved rather than left pending.
  • Requests are blocked unexpectedly: Narrow the predicate and inspect the URL, method, or resource type being matched. A broad condition can catch traffic the page needs.
  • A request was already handled: Another listener or dependency may have resolved it first. Check request.isInterceptResolutionHandled() immediately before calling a resolution method.
  • A request reports failure but was not blocked: Compare the event and outcome. Aborting produces requestfailed; an HTTP status such as 404 or 503 is a response that finishes normally.

The Puppeteer API documentation identified for this guidance is version 25.12.0. Check the documentation for the version installed in your project before relying on version-specific behavior. The available API guidance does not establish every interaction with service workers, browser versions, or specialized request sources, so verify those cases in your own setup.

Or skip the browser setup

If your goal is to capture a website rather than control its individual browser requests, ScreenshotNeo provides a screenshot API and MCP server. Its API can return a screenshot or PDF in one request; it is not a replacement for Puppeteer request interception when you need to decide which requests a browser should make.

Example cURL request, using the documented API parameters (see the ScreenshotNeo API documentation):

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

ScreenshotNeo removes supported cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, with no card required.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.