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

  1. Call await page.setRequestInterception(true) before navigating
  2. In page.on('request', ...), check interceptedRequest.resourceType() (returns a lowercase type like 'image', 'stylesheet', or 'font') and call .abort() for unwanted types, .continue() otherwise
  3. Guard the handler with interceptedRequest.isInterceptResolutionHandled() first, since Puppeteer throws if abort/continue/respond is called twice on the same request
  4. 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
  5. Navigate with page.goto(url) only after the request handler is registered

Known gotchas

Related routes

Generate a Puppeteer PDF with custom header/footer templates and controlled page breaks
pptr.dev · 5 steps · unrated
use puppeteer's locators api for auto-waiting, retrying element interactions
pptr.dev · 5 steps · unrated

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?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans