Abort image/stylesheet/font requests in Puppeteer by resource type, safely alongside other request interceptors
domain: pptr.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
Call await page.setRequestInterception(true) before navigating
In page.on('request', ...), check interceptedRequest.resourceType() (returns a lowercase type like 'image', 'stylesheet', or 'font') and call .abort() for unwanted types, .continue() otherwise
Guard the handler with interceptedRequest.isInterceptResolutionHandled() first, since Puppeteer throws if abort/continue/respond is called twice on the same request
If this interceptor coexists with another one on the same page, pass a numeric priority to abort()/continue()/respond() to opt into Cooperative Intercept Mode, where the highest-priority resolution wins
Navigate with page.goto(url) only after the request handler is registered
Known gotchas
Any single handler that resolves a request without a priority argument reverts the whole exchange to legacy first-caller-wins mode, even if other handlers used Cooperative Mode — mixing styles produces surprising outcomes
Once interception is enabled, every request stalls until it is aborted/continued/responded — forgetting to resolve even uninteresting requests hangs the page load
There is no dedicated 'block resource type' helper in current Puppeteer — resourceType()-based filtering plus abort/continue remains the only mechanism
Give your agent this knowledge — and 15,500+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?