Enable interception with await page.setRequestInterception(True) before navigating, then handle each request event by calling await request.continue_(), await request.abort(), or await request.respond(...). Every intercepted request must be resolved; otherwise it can stall. The example below blocks image requests and lets everything else proceed.
Intercept requests with a complete Python example
Pyppeteer exposes interception on a page. Turn it on before the navigation or other page activity you want to control, then register a handler for the page’s request event. The event callback itself is synchronous, so schedule the asynchronous handler with asyncio.ensure_future, as in the project’s documented pattern.
import asyncio
from pyppeteer import launch
async def main():
browser = await launch()
try:
page = await browser.newPage()
await page.setRequestInterception(True)
async def intercept(request):
if request.url.lower().split("?", 1)[0].endswith((".png", ".jpg", ".jpeg", ".gif", ".webp")):
await request.abort()
else:
await request.continue_()
page.on("request", lambda request: asyncio.ensure_future(intercept(request)))
await page.goto("https://example.com")
await page.screenshot({"path": "page.png", "fullPage": True})
finally:
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
The filter strips a query string before checking common image extensions, so a URL such as photo.jpg?width=800 is still matched. It is only an illustration: a site may serve images from extensionless URLs, and blocking images may make the page look incomplete. If images are needed, remove the image condition and continue all requests.
The authoritative Pyppeteer example and API names are documented in the Pyppeteer page.py source and its API reference. The reference is labeled version 0.0.25, so check the version installed in your environment when relying on version-specific details.
#1 Best Overall
Resolve every intercepted request
After interception is enabled, each request waits until it is continued, aborted, or fulfilled with a response. A conditional handler therefore needs a final branch: requests that do not match the rule must still be continued or otherwise resolved. This includes document requests, scripts, stylesheets, and application calls that are not the target of your filter.
await request.continue_()lets the browser make the request.await request.abort()cancels it. The documented default error code isfailed; the older reference also lists codes such asaborted,blockedbyclient,internetdisconnected,namenotresolved, andtimedout.await request.respond({...})supplies a response instead of fetching the resource normally.
Keep the handler simple and ensure exceptions do not leave requests unresolved. During development, log the URL and chosen action for rules that are difficult to verify. If an error occurs before a resolution call, the request may remain stalled; add exception handling that attempts an appropriate fallback only when the request has not already been resolved.
Choose a rule: URL, resource type, or a narrow target
Match URLs when the rule is about a particular endpoint
URL matching is useful for blocking a known path or substituting a response for a particular API endpoint. The suffix example is easy to read, but extension checks are inherently incomplete: servers can use query strings, redirects, extensionless paths, or different formats. Normalize the URL and make the rule as narrow as the requirement permits.
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Match resource types when the policy is about content classes
Pyppeteer’s request API documents resource types including document, stylesheet, image, media, font, script, texttrack, xhr, fetch, eventsource, websocket, manifest, and other. A policy aimed at images can use the request’s resource type rather than guessing from URL spelling. The Chrome for Developers example illustrates an allowlist approach that retains document, script, XHR, and fetch traffic: Headless Chrome and server-side rendering.
Free tools Windows power users keep installed
One-click scans. No signup required.
Do not blindly block a type just to reduce traffic. Stylesheets affect layout, fonts affect rendering, scripts and API calls often drive application behavior, and even images may be necessary to the result you are trying to capture. Start with the smallest scope, inspect the page outcome, and broaden the rule only if appropriate.
Modify a request or return a local response
Continue with overrides
Request.continue_(overrides=None) continues a request. The older Pyppeteer API reference documents overrides for url, method, and postData. For example, changing a URL can redirect a request to a test endpoint; changing the method or body can alter a request sent by the page. These override names and support are version-sensitive, so consult the API for the Pyppeteer version you actually use before depending on them.
Rank #3
Fulfill a request with a synthetic response
Request.respond(response) can provide a response without fetching the normal resource. The documented response dictionary supports status (default 200), optional headers, contentType, and body, which may be text or bytes. For example, a test could provide a small JSON body for a matching API route. Use a content type that matches the body and the page’s expectations; a syntactically valid response can still break application code if it does not match the expected schema.
Use synthetic responses for controlled tests or predictable fixtures, not as evidence that the live endpoint is healthy. Document which URLs are overridden so that a test result is not mistaken for behavior from the site itself.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteObserve requests, responses, completion, and failures
Interception controls outgoing requests; it is distinct from simply recording what happened. Pyppeteer documents these page events:
Rank #4
- 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
request: the page issued a request.response: a response arrived, if one did.requestfinished: the response body downloaded and the request completed.requestfailed: the request failed, potentially instead of producing a response or a finished event.
A redirect is not necessarily a single request object: the original request finishes and the browser makes another request to the redirect destination. If you are recording a navigation chain, track the sequence rather than assuming one request represents every redirect hop.
Avoid copying current Puppeteer-only safeguards blindly
Pyppeteer and Puppeteer have related APIs, but their documentation and versions are not interchangeable. Pyppeteer’s located reference is version 0.0.25. The current Puppeteer network interception guide (API page labeled 25.12.0) describes multiple-handler safeguards: check whether another listener has already resolved an intercepted request before acting, and check again after asynchronous work. The cited Pyppeteer reference does not establish that these methods exist in every Pyppeteer installation. Do not paste those safeguards into Pyppeteer code without verifying your installed version’s API.
Regardless of version, avoid registering competing handlers that can each try to resolve the same request. If your application or a library installs additional listeners, confirm how that combination behaves in your specific Pyppeteer version.
Best Value
Troubleshooting request interception
- Navigation hangs after enabling interception: a handler branch may have omitted
continue_(),abort(), orrespond(), or the asynchronous handler raised before resolving the request. Add logging around the decision and ensure every path handles the request. - The page is missing content or behaves incorrectly: the filter may have blocked a stylesheet, script, font, image, or API request the page needs. Narrow the rule, allow the required resource type or endpoint, and compare the page with interception disabled.
- Your URL rule misses requests: the URL may include a query string, use a different extension, redirect, or omit a file extension. Inspect actual request URLs and use resource type when the rule concerns a class of resource.
- A request unexpectedly fails: distinguish a deliberate abort from a network failure by logging the rule and observing
requestfailed. A response event is not guaranteed for a failed or aborted request. - An override or newer API raises an attribute or argument error: confirm the installed Pyppeteer version and use its own API reference. Current Puppeteer examples may document methods or behavior absent from the older Pyppeteer version.
Performance, reliability, and cost considerations
Interception gives your code control over each request, but also adds a handler decision to the request path. Keep filtering work lightweight and avoid unnecessary waits in the handler. There is no documented performance figure here that would justify promising a specific speedup or bandwidth saving. Blocking resources can reduce transferred content in some workflows, but can also alter rendering or functionality; measure the behavior that matters for your own page and rule set.
For reliable automation, enable interception before the activity to be observed, resolve requests consistently, and keep a record of the applied policy. Test both matching and nonmatching URLs, including redirects and failure cases relevant to your target. Treat browser/network errors separately from intentional aborts so that a blocked request is not misdiagnosed as an outage.
Or skip the browser setup
If your goal is a screenshot rather than custom request-level behavior, ScreenshotNeo offers a screenshot API and MCP server. It cannot replace arbitrary Pyppeteer interception rules, but can handle common clean-capture work without setting up a browser. One GET request returns an image or PDF. See the ScreenshotNeo API documentation for options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
- Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each cleanup step can be turned off.
- Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed; response headers identify the page verdict and billing status.
- An MCP server provides
take_screenshot,get_page_info, andcapture_pdftools for AI agents and other MCP clients. - The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for 1,000 free screenshots a month, with no card required.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteFrequently Asked Questions
Does request interception automatically capture response bodies?
No. Interception is for controlling requests; use response-related events and the relevant response APIs when your task is to observe responses.
Can I intercept requests only after a page has loaded?
You can enable it for later page activity, but it cannot retroactively control requests already sent. Enable it before the navigation or action whose requests you need to handle.
Quick Recap
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.

