Skip to Content
Request Interception

Request Interception — Block and Modify HTTP Requests

Foxbridge implements the CDP Fetch domain for request interception, translating to Juggler’s Browser.setRequestInterception API.

Enabling Interception

// Via Puppeteer await page.setRequestInterception(true); page.on('request', request => { if (request.url().includes('ads')) request.abort(); else request.continue(); });

Under the hood, Puppeteer calls Fetch.enable which foxbridge translates to:

Fetch.enable → Browser.setRequestInterception({enabled: true})

The browserContextId is automatically resolved from the CDP session.

Supported Methods

CDP MethodJuggler MethodDescription
Fetch.enableBrowser.setRequestInterceptionStart intercepting requests
Fetch.disableBrowser.setRequestInterception(false)Stop intercepting
Fetch.continueRequestBrowser.continueInterceptedRequestContinue with optional URL/header modifications
Fetch.fulfillRequestBrowser.fulfillInterceptedRequestRespond with custom status/headers/body
Fetch.failRequestBrowser.abortInterceptedRequestFail with an error reason
Fetch.continueWithAuthBrowser.handleAuthRequestHandle HTTP auth challenges
Fetch.getResponseBodyBrowser.getResponseBodyRead intercepted response body
Fetch.continueResponseBrowser.continueInterceptedRequestContinue with modified response headers

Error Reason Mapping

Fetch.failRequest accepts a CDP Network.ErrorReason which is mapped to Juggler error codes:

CDP ErrorReasonJuggler Code
Failedfailed
Abortedaborted
TimedOuttimedout
AccessDeniedaccessdenied
ConnectionRefusedconnectionrefused
NameNotResolvednamenotresolved
InternetDisconnectedinternetdisconnected
BlockedByClientblockedbyclient
BlockedByResponseblockedbyresponse

Event Flow

When a request is intercepted, Juggler emits Browser.requestIntercepted. Foxbridge translates this into two CDP events in order:

  1. Network.requestWillBeSent — so Puppeteer has the request metadata
  2. Fetch.requestPaused — so Puppeteer knows to call continue/abort/fulfill

The requestId is shared between both events. Foxbridge resolves the correct CDP session from the request’s frameId.

Response Body

Fetch.getResponseBody returns the body from Juggler’s base64-encoded format. If the content is valid UTF-8 text, it is decoded and returned as plain text (base64Encoded: false). Binary content is returned as-is with base64Encoded: true.

BiDi Backend

On the BiDi backend, request interception uses network.addIntercept with the beforeRequestSent phase. Intercept IDs are tracked for cleanup when interception is disabled.


See also

Last updated on