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:Getgauge Taiko Request Interception Setup

From Leeroopedia

Template:Principle

Overview

Request Interception Setup is the foundational technique for configuring browser-level HTTP request interception to control, modify, or mock network traffic during automated testing with Taiko.

Description

Request interception enables pausing outgoing HTTP requests before they reach the network and taking programmatic action — blocking, redirecting, mocking responses, or modifying request details. This uses the Chrome DevTools Protocol (CDP) Fetch domain to intercept all network traffic matching specified URL patterns. When enabled, each matching request is paused and the automation code decides how to handle it. This is fundamental for testing applications in isolation from external dependencies.

The interception mechanism works transparently at the browser level, meaning the web application under test has no awareness that its requests are being intercepted. This allows realistic testing of network-dependent behaviors without requiring changes to application code or infrastructure.

Key capabilities enabled by request interception:

  • Blocking — Prevent specific requests from completing (e.g., analytics, ads)
  • Redirecting — Forward requests to alternative endpoints (e.g., mock servers)
  • Mocking — Return fabricated responses without network activity
  • Handling — Apply custom logic to dynamically decide request fate

Usage

Request interception is used when tests need to:

  • Isolate the application under test from external service dependencies
  • Simulate error conditions such as server failures or timeouts
  • Control the data returned by API endpoints for deterministic testing
  • Block unnecessary resources to speed up test execution
  • Verify that the application makes expected network requests

Theoretical Basis

The interception pipeline follows a well-defined sequence using the Chrome DevTools Protocol:

CDP Fetch.enable with wildcard pattern
        │
        ▼
Fetch.requestPaused event fires for each matching request
        │
        ▼
Match against registered interceptors (URL pattern matching)
        │
        ▼
Apply action based on interceptor configuration:
  ├── No action    → Fetch.failRequest (block)
  ├── String       → Fetch.continueRequest with new URL (redirect)
  ├── Object       → Fetch.fulfillRequest with mock data (mock)
  └── Function     → Invoke handler with continue/respond helpers
        │
        ▼
Request continues or is fulfilled

The Fetch.enable call is made with a wildcard URL pattern (*) so that all network requests pass through the interception layer. Each intercepted request triggers a Fetch.requestPaused event, which the fetch handler processes by checking registered interceptors. If a matching interceptor is found, its configured action is applied. If no interceptor matches, the request is allowed to continue normally via Fetch.continueRequest.

Interceptors support both exact URL matching and regular expression patterns, providing flexibility in targeting specific requests or groups of requests.

The optional count parameter allows interceptors to automatically deregister after a specified number of matches, which is useful for one-shot mocking scenarios.

Related Pages

Implemented By

Page Connections

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