Copying and Replaying Requests
What you'll learn: How to extract network requests from DevTools and replay them outside the browser for debugging and testing.
The Concept
Sometimes you need to investigate an API call without reloading your entire application, or you want to debug a request in a different environment. Browser DevTools let you copy any network request as executable code in various formats—cURL commands, JavaScript fetch() calls, or Node.js code—so you can replay that exact request anywhere.
Think of it like recording a conversation and playing it back: you capture every detail of the HTTP request (URL, headers, body, method) and recreate it perfectly in a terminal, script, or testing tool.
How It Works
In the Network panel, right-click any completed request and choose "Copy" from the context menu. You'll see options like:
- Copy as cURL: Creates a command-line instruction you can paste into your terminal
- Copy as fetch: Generates JavaScript code using the Fetch API
- Copy as Node.js fetch: Similar, but formatted for Node.js environments
Each format includes all relevant details: authentication headers, request body, cookies, and more. This is incredibly useful when:
- A backend developer needs to reproduce your exact API call
- You want to test requests with modified headers or payloads
- You're building automation scripts or tests
- You need to debug authentication or CORS issues outside the browser
Example Use Case
You notice a POST request failing intermittently. Copy it as cURL, paste it into your terminal, and run it repeatedly to isolate whether the issue is browser-specific, timing-related, or server-side.
Key Takeaway: Copying requests as cURL, fetch, or Node.js code lets you replay and debug API calls outside the browser, making it easier to isolate problems and share reproducible examples.