Principle:Cypress io Cypress Browser Test Execution
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Proxy |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A proxy-based browser instrumentation technique that intercepts and rewrites HTTP traffic to inject test instrumentation into the application under test.
Description
Browser test execution in Cypress uses a fundamentally different approach from tools like Selenium. Instead of controlling the browser via an external protocol (WebDriver), Cypress runs directly inside the browser alongside the application. To achieve this, all HTTP/HTTPS traffic flows through a local proxy that can rewrite JavaScript and HTML on the fly.
The JavaScript rewriter uses AST (Abstract Syntax Tree) transformation to modify application code for cross-origin support, source map handling, and test instrumentation. The HTTPS proxy generates dynamic certificates using a local Certificate Authority to transparently intercept HTTPS traffic.
Usage
Use this principle when understanding how Cypress achieves in-browser test execution. It applies during every test run, as all application traffic is proxied through the Cypress server.
Theoretical Basis
Proxy Architecture:
Browser → HTTP Proxy (packages/proxy/) → Target Server
Browser → HTTPS Proxy (packages/https-proxy/) → Target Server
JavaScript Rewriting Pipeline:
1. Intercept JS response
2. Parse JavaScript into AST (via recast/ast-types)
3. Apply transformation rules (window references, location, etc.)
4. Serialize modified AST back to JavaScript
5. Optionally rewrite source maps
6. Return modified JavaScript to browser