October 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 PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
browser automation

How to Abort Puppeteer Requests After a Timeout

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

To abort a particular Puppeteer request, enable request interception and resolve that request with request.abort('timedout') when your deadline expires. The catch is important: interception pauses a request until you continue, respond to, or abort it. If you keep it paused while a timer runs, the timer measures how long it has been held by your handler—not how long it has spent loading from the server. If you continue it immediately, a later timer cannot abort it through that interception.

That makes request interception useful for a deliberate per-request decision, but not a transparent way to let every request run normally and then cancel just the slow ones. First decide whether you need to abort a specific request or merely stop waiting for a page operation; Puppeteer has different mechanisms for those jobs.

Choose the timeout that matches what you want to stop

A timeout can apply to one HTTP request, a Puppeteer wait or navigation, or browser startup. Those scopes are not interchangeable. In particular, a wait timing out does not mean that you explicitly aborted a chosen HTTPRequest.

Goal Mechanism What the deadline applies to
Decide whether a specific intercepted request should proceed or be canceled page.setRequestInterception(true) and resolve the request with abort(), continue(), or respond() The request while it is held for your interception policy. A timer started in the request handler starts when that handler receives it.
Stop waiting for a Puppeteer wait operation The wait method’s timeout option or, where supported, signal The wait, not a specific network request.
Limit how long navigation waits The applicable page navigation timeout setting or the navigation method’s options The navigation operation. Confirm the method and behavior against your installed Puppeteer version.
Limit browser startup The browser launch option timeout Waiting for the browser to start, not page traffic.

Puppeteer’s documented wait-option default is 30,000 ms; setting timeout: 0 disables that timeout. The documented browser launch timeout default is also 30,000 ms. Check the API documentation for the version your project installs before relying on a particular wait method’s options.

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

Abort a request held by interception

This pattern is appropriate when your policy intentionally holds each request briefly and then either aborts it or lets it proceed. It installs one timer per request, clears the timer when the request finishes or fails, and checks that the interception has not already been resolved before acting.

const requestTimers = new WeakMap();
const requestTimeoutMs = 10_000;

await page.setRequestInterception(true);

page.on('request', request => {
  // Another handler may have resolved this request already.
  if (request.isInterceptResolutionHandled()) return;

  const timer = setTimeout(() => {
    // Check again immediately before resolving the interception.
    if (request.isInterceptResolutionHandled()) return;

    void request.abort('timedout').catch(() => {});
  }, requestTimeoutMs);

  requestTimers.set(request, timer);
});

function clearRequestTimer(request) {
  const timer = requestTimers.get(request);
  if (timer) clearTimeout(timer);
  requestTimers.delete(request);
}

page.on('requestfinished', clearRequestTimer);
page.on('requestfailed', clearRequestTimer);

In this example, the handler deliberately does not call continue() immediately: doing so would resolve the interception and remove the ability to abort it later through this handler. As written, requests are held until the timer fires, then aborted. To make a different decision—such as allowing a request to proceed—add a clearly defined settlement path that calls continue() before the deadline and clears its timer. Do not leave requests indefinitely unresolved.

This is a deadline for a request that remains intercepted. It is not a way to measure server response time while the request is already flowing normally. If your requirement is “let this request run, but cancel it if its network transfer takes too long,” the pattern above does not provide that behavior: continuing resolves the interception, so its timer cannot later abort that request with the same interception.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Why timer cleanup matters

The requestfinished and requestfailed events are useful cleanup points. A completed request should not retain a timer that might later try to act on it. An abort is a request failure, so the failure event also gives your cleanup function a chance to run. The WeakMap associates each timer with its request without requiring a separate global list.

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

Keep resolution single and intentional

Every intercepted request needs a resolution: continue it, respond to it, or abort it. Check request.isInterceptResolutionHandled() before resolving, and check again immediately before the action if your handler has awaited asynchronous work. Another event listener or dependency can settle the request while that work is pending. Catching a rejected action avoids an unhandled promise rejection if the request has already become unavailable, but it does not replace the handled-state check.

Handle multiple interception handlers safely

Page-wide interception can interact with listeners installed by your own code, libraries, or dependencies. If another handler resolves a request first, your timer’s later abort may no longer be valid. The handled-state check is therefore part of correctness, not just defensive style.

Puppeteer also documents Cooperative Intercept Mode. Its priority rules apply when handlers pass numeric priorities. Among equal-priority resolutions, abort takes precedence over respond, which takes precedence over continue. A handler that resolves without a priority uses legacy behavior and resolves immediately; cooperative mode does not remove the need to check whether a request has already been handled. Do not assume a priority will protect a timer from another handler’s immediate resolution.

Distinguish network failure from an HTTP error response

Use the request lifecycle to observe what happened. A request aborted by Puppeteer is a network-level failure and is reported through requestfailed. An HTTP status such as 404 or 503 is different: it is an HTTP response, and the request can finish through requestfinished. Do not infer that an HTTP error status means Puppeteer aborted or failed the request.

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

request.failure() can provide an error string for a failed request, but Puppeteer does not guarantee the exact text. Base program logic on the event and your own timeout policy rather than matching an assumed error message.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Common problems and fixes

  • Requests appear frozen after enabling interception. Interception pauses requests until they are continued, responded to, or aborted (with browser-cache completion as an exception). Install a handler that resolves every request before enabling interception, and ensure every code path settles it.
  • The timer fires, but the request still completes. Check whether your handler called continue() first or whether another handler resolved it. Once interception is resolved, the timer cannot later use that interception to abort the request.
  • Your “10-second request timeout” feels shorter or longer than expected. A timer created in the request event measures time since the handler received the request. If it remains intercepted, it has not been released to proceed normally. Decide whether you need a held-request policy or an operation timeout instead.
  • An abort action rejects or does nothing useful. Another handler may have resolved the request, or the request may no longer be available. Recheck isInterceptResolutionHandled() immediately before the action and provide a clear fallback policy.
  • A 404 or 503 is being counted as an abort. Treat HTTP statuses as responses, not as Puppeteer network failures. Inspect response status separately from the requestfailed lifecycle.
  • A navigation or wait timeout is mistaken for an individual request abort. These controls stop or bound a Puppeteer operation. If the requirement is explicitly to resolve one intercepted request, use request interception and track that request separately.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost considerations

Interception is page-wide, so enabling it affects more than the request you ultimately intend to cancel. A slow or missing resolution path can stall page loading. Keep handlers small, minimize asynchronous policy work, and scope interception to the pages or operations that need it. If you add asynchronous checks, recheck the handled state just before settling the request.

Choose timer scope deliberately. A per-request timer starts anew for each request. A shared deadline for a complete navigation or job is a different policy: it should bound that operation rather than reset every time the page makes another request. Mixing the two can make an operation run longer than intended. No single timeout value is suitable for every site or request; choose it from your application’s tolerance and test both slow and failing cases.

Also distinguish a timeout from a retry policy. Aborting a request does not, by itself, establish whether retrying is safe or useful. Retrying a read-only asset may be harmless in some applications; retrying a state-changing request may duplicate an action. Decide at the application layer which requests may be retried, how many attempts are allowed, and whether a retry shares the original operation deadline.

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

Or skip the browser setup

If your goal is to obtain a website screenshot rather than manage Puppeteer’s individual network requests, ScreenshotNeo provides a screenshot API and MCP server. It does not give you Puppeteer’s per-request abort control; it is an alternative for the screenshot task itself. One GET request can return a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation.

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; each cleanup step 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. Its MCP server exposes screenshot tools for AI clients. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Check your installed Puppeteer version

The current Puppeteer documentation pages reviewed for this topic surfaced version labels 25.10.0, 25.11.0, and 25.12.0. API options can vary by version, so verify the installed package’s documentation—especially the exact wait method and navigation behavior—before relying on defaults or cancellation options. The interception concepts above describe the distinction between resolving an intercepted request and timing out a wait; they should not be read as a claim that the sample was executed against every version.

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

Frequently Asked Questions

Does a timeout option on a Puppeteer wait abort one particular HTTP request?

No. It bounds the wait operation. To explicitly resolve one intercepted request, use that request’s interception policy.

Can an HTTP 503 trigger Puppeteer’s requestfailed event?

Not merely because it is a 503. It is an HTTP response; network failure and HTTP status are separate outcomes.

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.

Read next

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.