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 Redirect

From Leeroopedia

Template:Principle

Overview

Request Redirect is the technique for transparently redirecting HTTP requests from one URL to another at the browser level during automated testing with Taiko.

Description

Request redirect intercepts requests matching a URL pattern and forwards them to a different URL. The browser processes the redirected response as if it came from the original URL, making the redirect transparent to the web application under test. This is achieved through the CDP Fetch.continueRequest method with an overridden URL parameter.

Unlike HTTP-level redirects (301/302), this interception-based redirect happens at the browser protocol level. The application's JavaScript code sees the response as coming from the original URL, with no redirect status codes or location headers. This makes it particularly useful for seamless URL substitution.

Key use cases for request redirection:

  • Pointing API calls to mock servers — Redirect production API endpoints to local or staging mock servers without changing application configuration
  • Replacing CDN resources with local versions — Serve modified CSS, JavaScript, or images from local files during testing
  • Testing URL migration scenarios — Verify that an application works correctly when backend endpoints change
  • Environment switching — Redirect requests from one environment (production) to another (staging, development) transparently

Usage

Request redirection is used when the test needs the request to complete successfully but with a different target server or path. The redirect URL must be a valid URL; it is validated before the interceptor is registered.

This technique preserves the original request method, headers, and body — only the URL is changed. The response from the redirect target is returned to the application as if it originated from the original URL.

Theoretical Basis

The redirect mechanism operates through URL substitution at the CDP level:

intercept(originalUrl, redirectUrl) called with string action
        │
        ▼
redirectUrl is validated as a proper URL
        │
        ▼
Interceptor registered with action = redirectUrl (string)
        │
        ▼
Matching request is paused by Fetch.requestPaused
        │
        ▼
handleInterceptor checks action → typeof string
        │
        ▼
Fetch.continueRequest({
    requestId,
    url: redirectUrl    ← URL is replaced
})
        │
        ▼
Browser sends request to redirectUrl instead of originalUrl
        │
        ▼
Response is returned to application as if from originalUrl

The redirect is performed using Fetch.continueRequest with the url override. This CDP method allows modifying the request before it proceeds to the network. Only the URL is changed; all other request properties (method, headers, body) are preserved from the original request.

The URL validation step ensures that the redirect target is a well-formed URL, preventing cryptic network errors from malformed destinations.

Related Pages

Implemented By

Page Connections

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