ZeroBloatTools
developer Utility
Updated 2026-10-26•5 min read

cURL to Playwright & Grafana k6 Test Script Converter

Convert cURL commands directly into clean Playwright APIRequestContext tests, Grafana k6 load test scripts, and route mock interceptors with automatic noise stripping and secret masking.

Interactive Studio
cURL Compiler Studio
Client-Side AST
Samples:
POST/v1/orders•3 headers
Raw cURL Input
AST Request InspectorParsed Cleanly
POSThttps://api.example.com/v1/orders
Query Params
1
Headers
3
Payload
JSON
Auto-masked 1 secret headers: Authorization → env vars
api.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { test, expect } from '@playwright/test';
test('POST /v1/orders', async ({ request }) => {
const response = await request.post("https://api.example.com/v1/orders", {
params: {
"notify": "true",
},
headers: {
"Authorization": `Bearer ${process.env.API_BEARER_TOKEN ?? ''}`,
"Content-Type": "application/json",
"X-Request-ID": "req_42",
},
data: {
"customerId": "cus_109",
"items": [
{
"sku": "PRO-PLAN",
"qty": 2
}
],
"currency": "USD"
},
});
// Verify HTTP status & response payload
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);
const body = await response.json();
expect(body).toBeDefined();
});
Terminal Execution:
npx playwright test api.spec.ts
Engineering & Technical Principles

How cURL Commands Translate into Playwright & k6 API Requests

A cURL command encapsulates an HTTP method, target endpoint, query parameters, request headers, cookies, and an optional body payload. When transitioning from exploratory debugging in Chrome DevTools, Postman, or terminal sessions to automated test suites, this converter tokenizes the raw shell syntax using an Abstract Syntax Tree (AST) tokenizer. It extracts query parameters into structured objects, identifies and formats JSON or Form-UrlEncoded data, strips ephemeral browser telemetry headers, and outputs idiomatic TypeScript or JavaScript code for Playwright and Grafana k6.

Key Technical Specifications:

  • POSIX and Bash AST tokenizer supporting multiline backslash line breaks and Chrome DevTools ANSI-C ($"...") quoted strings.
  • Automatic Chrome DevTools noise header filter removing sec-ch-ua, sec-fetch-*, connection, and accept-encoding headers that cause test fragility.
  • Intelligent secret masking that converts Authorization Bearer tokens, x-api-key, and session cookies into process.env.* or __ENV.* expressions.
  • Three dedicated target architectures: Playwright APIRequestContext (.spec.ts), Grafana k6 load testing scripts (.js), and Playwright page.route() network interceptors.

Step-by-Step: Converting Chrome DevTools or Postman cURL into Playwright

1

Copy the Network Request as cURL

In Chrome, Edge, or Firefox DevTools, navigate to the Network tab, right-click the HTTP request you want to test, and choose Copy > Copy as cURL (bash). In Postman or Insomnia, click Code Snippet > cURL.

2

Paste into the AST Converter

Paste the command into the input textarea. The real-time tokenizer immediately parses the HTTP method, pathname, query parameters, headers, and request payload without sending any data over the network.

3

Verify Noise Stripping and Secret Masking

Ensure "Strip DevTools Noise Headers" is checked to remove fragile browser-fingerprint headers (such as sec-ch-ua). Keep "Mask Auth Tokens" checked so sensitive API tokens are referenced via process.env or __ENV instead of being hardcoded.

4

Select Target Framework & Copy

Select either Playwright API, Grafana k6, or Playwright Route Mock depending on your testing objective. Click "Copy Code" or "Download" to save the generated test script directly to your project.

Diagnostics & Common Pitfalls

Top Troubleshooting Pitfalls & Solutions

Issue: Leaving browser-specific sec-ch-ua and sec-fetch-* headers in automated API tests.
Solution: 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.
Issue: Hardcoding production Bearer tokens or API keys into git-committed test files.
Solution: 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.
Issue: Using page.goto() instead of Playwright APIRequestContext for REST testing.
Solution: 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

Frequently Asked Questions: cURL to Playwright & k6

What is Playwright APIRequestContext and why use it for API testing?

APIRequestContext is Playwright's built-in HTTP client designed specifically for API testing. It runs directly on Node.js without spinning up a Chromium, Firefox, or WebKit browser engine, making test execution 10x-50x faster. It automatically shares cookies and storage state with browser contexts when performing authenticated end-to-end testing.

Is my cURL command or API key uploaded to your server?

No. This tool operates 100% on the client side inside your web browser. The cURL command is tokenized and compiled in JavaScript on your machine. Zero requests or payloads are transmitted to any backend server or third-party service.

How do I handle multipart/form-data or file uploads in Playwright?

When sending multipart file uploads, Playwright provides the multipart option instead of data. In your test, you pass { multipart: { file: fs.createReadStream("path/to/file.png") } }. This converter detects form data payloads and flags them in the inspector.

How do I run the generated Grafana k6 load test script?

Install k6 on your machine (brew install k6 on macOS, choco install k6 on Windows, or via docker), and run: k6 run --vus 10 --duration 30s generated-request.k6.js. You can pass masked environment variables using the -e flag: k6 run -e API_BEARER_TOKEN="your_token" ...

What is the difference between Playwright API test and Playwright page.route() mock?

A Playwright API test makes a live outbound HTTP request to your backend server and validates the actual response. A page.route() mock intercepts an outgoing request made by your frontend UI inside a real browser and fulfills it immediately with synthetic JSON data, allowing you to test edge cases (e.g. 500 errors, empty states) without relying on a live backend.

Why does Chrome DevTools Copy as cURL include $'...' syntax?

Chrome DevTools uses Bash ANSI-C quoting ($"...") when request payloads or headers contain escape sequences like newlines (\n) or single quotes. Our converter engine includes a native ANSI-C string parser that unescapes these sequences cleanly into standard JSON.