Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Puppeteer Puppeteer Request Handling

From Leeroopedia
Revision as of 18:11, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Puppeteer_Puppeteer_Request_Handling.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Browser_Automation, Networking, Testing
Last Updated 2026-02-11 23:00 GMT

Overview

A set of operations that resolve intercepted HTTP requests by continuing, aborting, or responding with custom data.

Description

Request Handling provides three resolution strategies for intercepted HTTP requests:

  • Continue: Forward the request to the network. Optionally modify the URL, method, headers, or POST data before forwarding.
  • Abort: Cancel the request and return an error to the page. Useful for blocking unwanted resources.
  • Respond: Fulfill the request with a custom response without touching the network. Useful for mocking APIs and injecting test data.

Puppeteer supports cooperative intercept handling: multiple handlers can be registered for request events, and a priority-based resolution system determines the final action. This enables layering interceptors (e.g., one for authentication headers, another for ad blocking).

Usage

Use request handling within request interception handlers (registered via page.on('request', ...)). Every intercepted request must be resolved with exactly one of these three methods. Failing to call any of them will cause the request to hang indefinitely.

Theoretical Basis

# Request resolution decision tree
intercepted_request:
  if should_block(request):
    request.abort('blockedbyclient')
  else if should_mock(request):
    request.respond({status, headers, body})
  else if should_modify(request):
    request.continue({url, method, headers, postData})
  else:
    request.continue()  // pass through unchanged

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment