ZeroBloatTools LogoZeroBloatTools
Verified Preset100% Client-Side
Updated 2026-11-15•Instant Calculation

cURL to Playwright page.route() Network Mock Converter

Pre-loaded with a GraphQL POST query compiled into Playwright `page.route()` interception code so UI tests run deterministically offline.

Interactive Pre-Configured Simulator
cURL Compiler Studio
Client-Side AST
Samples:
POST/graphql•2 headers
Raw cURL Input
AST Request InspectorParsed Cleanly
POSThttps://api.example.com/graphql
Query Params
0
Headers
2
Payload
JSON
Auto-masked 1 secret headers: X-Api-Key → env vars
mock.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { test, expect } from '@playwright/test';
test('Mock POST /graphql network request', async ({ page }) => {
await page.route('**/graphql*', async (route) => {
if (route.request().method() !== 'POST') {
return route.fallback();
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
"query": "query GetUser($id: ID!) { user(id: $id) { id email role } }",
"variables": {
"id": "usr_88"
}
}),
});
});
await page.goto("https://api.example.com");
await expect(page).toHaveURL(/api\.example\.com/);
});
Terminal Execution:
npx playwright test api.spec.ts
Request Translation Reference

Playwright page.route() Interception Patterns

Turn live API requests captured from DevTools into fast, isolated UI test mocks.

Route PhasePlaywright APITarget MatchAuth / Noise RuleTesting Benefit
URL Matcherpage.route('**/graphql', ...)Pathname GlobMethod GuardIntercepts frontend fetch/XHR calls inside Chromium/WebKit
Method Checkroute.request().method() === 'POST'Fall-Throughroute.fallback()Avoids accidentally mocking preflight OPTIONS requests
Synthetic Fulfillroute.fulfill({ status: 200, json })Instant Response0 ms LatencyTest empty states, 500 errors, and rate limits cleanly
Playwright APIRequestContext Patterns

Header Normalization, Auth & Payload Mapping

  • Intercepting `/graphql` or REST routes in browser UI tests eliminates flaky staging database state and cuts test runtime drastically.
  • Preserves HTTP method matching (`POST`) inside `page.route()` callbacks and passes unmatched verbs cleanly via `route.fallback()`.
  • Lets QA engineers test error HTTP 429/500 UI fallback states that are difficult to reproduce against live staging servers.
Common cURL Conversion Bugs

Critical Errors to Avoid

Common Error: Leaving browser-specific sec-ch-ua and sec-fetch-* headers in automated API tests.
Best Practice: Browser headers like sec-ch-ua-mobile or sec-fetch-dest indicate browser state and change across browser versions. In headless CI test runs, leaving them in can trigger Cloudflare, Datadog, or AWS WAF anti-bot blocks due to header mismatch. Always strip browser-only headers from backend API tests.
Common Error: Hardcoding production Bearer tokens or API keys into git-committed test files.
Best Practice: Avoid committing raw credentials. Keep secret masking enabled to replace Authorization tokens with environment variables (process.env.API_BEARER_TOKEN), and supply the real secret via your .env file or GitHub Actions secrets.
Common Error: Using page.goto() instead of Playwright APIRequestContext for REST testing.
Best Practice: Testing backend APIs by navigating a full browser page adds massive CPU and memory overhead (rendering HTML, parsing CSS, running client JS). Use Playwright's built-in request fixture (APIRequestContext), which executes direct HTTP requests at Node.js network speeds without launching a browser window.
Frequently Asked Questions

cURL GraphQL Query to Playwright page.route() Mock Questions Answered

When should I use page.route() mocks instead of Playwright APIRequestContext?

Use `APIRequestContext` (`request.post`) when integration-testing your backend endpoints directly. Use `page.route()` mocks when testing React/Next.js UI behavior so frontend suites run fast and deterministically without database side effects.

How do I inspect the GraphQL query name inside page.route()?

Call `const body = route.request().postDataJSON();` inside the handler to branch responses by `body.operationName` or `body.variables`.

Common cURL Flags Cheat Sheet

-X, --request:
HTTP Method (GET, POST, PUT, DELETE, PATCH, HEAD)
-H, --header:
Request Header ("Header-Name: value")
-d, --data, --data-raw:
HTTP Request Body / Payload (JSON, Form-UrlEncoded, Text)
-u, --user:
Basic Authentication ("username:password")
-b, --cookie:
HTTP Cookie header ("name=value; session=123")
-k, --insecure:
Allow insecure SSL/TLS connections during local testing
Security & Credential Hygiene

Security & Client-Side Privacy Notice

100% Client-Side Processing: This utility parses and generates code entirely in your local browser using an in-memory AST tokenizer. Your cURL commands, secret tokens, endpoints, and data payloads are never sent to any external server.
Environment Secret Hygiene: Always keep "Mask Auth Tokens" checked before pasting curl commands with production credentials. Never commit raw Bearer tokens, cookies, or private API keys to git repositories.