User Agents

Web browsers and everyday web tech, explained

Extract Curl Request from Chrome DevTools

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Extracting a cURL request from Chrome DevTools allows you to replicate a web request made by your browser in a terminal or script, preserving all headers, cookies, and payload data. This is useful for debugging, testing APIs, or automating interactions with web services. Chrome DevTools provides a built-in feature to copy any network request as a cURL command, making it easy to inspect and reuse HTTP calls outside the browser.

What You'll Need

  • Google Chrome or a Chromium-based browser (e.g., Microsoft Edge, Brave)
  • A website or web application that makes HTTP requests (e.g., API calls, form submissions)
  • Basic familiarity with the browser’s Developer Tools interface
  • A terminal or command-line environment to run the cURL command (optional, for testing)

Step-by-Step

  1. Open the webpage where the request you want to capture is made. This could be a login form, an API endpoint triggered by a button, or any dynamic content loaded via JavaScript.
  2. Right-click anywhere on the page and select Inspect from the context menu, or press Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac) to open Chrome DevTools.
  3. Navigate to the Network tab in DevTools. If no requests are visible, reload the page while DevTools is open to capture all network activity.
  4. Perform the action that triggers the HTTP request you want to extract. For example, submit a form, click a button that loads data, or search for content.
  5. In the Network tab, locate the specific request in the list. You can filter by type (e.g., XHR, Fetch, JS, All) or use the search bar to find the endpoint by name or URL.
  6. Click on the request to open its detailed view. This shows headers, timing, response, and other metadata.
  7. Right-click on the selected request in the list (not inside the detail pane) to open the context menu.
  8. From the context menu, hover over or click Copy, then select Copy as cURL (or Copy as cURL (bash) in some versions).
  9. A complete cURL command will be copied to your clipboard. It includes the URL, HTTP method, headers (like User-Agent, Authorization, cookies), and any request body data.
  10. Paste the command into a terminal, script, or text editor. You can now run it directly or modify it for testing, automation, or debugging.

Common Mistakes

  • Copying from the wrong tab: Ensure you are in the Network tab, not Console or Elements. The cURL option only appears in the Network panel.
  • Missing the request: If you don’t see the request, reload the page with DevTools open. Requests made before opening DevTools won’t appear.
  • Not triggering the request: Some requests only occur after user interaction. Simply loading the page may not capture dynamic API calls.
  • Overlooking filters: The Network tab may filter out certain request types. Set the filter to All or XHR to ensure visibility.
  • Using an outdated cURL: Some headers or syntax (like --compressed) may not be supported in older cURL versions. Update if commands fail.

Tips

  • Use Preserve log: Enable the Preserve log checkbox in the Network tab to keep requests visible across page navigations or reloads.
  • Inspect request details first: Before copying, review the Headers and Payload tabs to confirm the request includes necessary data like authentication tokens or form fields.
  • Copy as cURL (cmd) for Windows: If working in Command Prompt or PowerShell, choose Copy as cURL (cmd) for proper escaping of quotes and special characters.
  • Remove unnecessary headers: The copied cURL includes many headers (e.g., Accept-Encoding, Connection). For testing, you can safely remove non-essential ones unless the server requires them.
  • Handle cookies carefully: If the request relies on session cookies, ensure they are included. Clearing cookies or using a different session may cause authentication failures.

Troubleshooting

If the cURL command fails when executed, consider the following:

  • 403 Forbidden or 401 Unauthorized: The request may require valid authentication. Check if the copied headers include an Authorization token or session cookie. These may expire quickly, so copy and use the command immediately.
  • 400 Bad Request: The server may reject malformed headers or payloads. Compare the original request in DevTools with the cURL output. Ensure all JSON or form data is correctly formatted.
  • SSL/TLS errors: Some cURL versions may have certificate verification issues. Use --insecure only for testing, but never in production, as it disables SSL verification.
  • Syntax errors in terminal: On Unix-like systems, ensure special characters (like single quotes or ampersands) are properly escaped. Using Copy as cURL (bash) helps prevent this.
  • Request not appearing: Disable browser extensions that may block requests (e.g., ad blockers). Test in an incognito window with extensions disabled.
  • Missing request body: For POST requests, verify the Payload tab shows data. If empty, the request might be sent via JavaScript without a body, or the copy may have failed—try again.

Frequently Asked Questions

Can I copy cURL commands from other browsers?

Yes, Firefox and some other browsers offer similar features under Network tools, but the exact steps and output format may vary.

Does copying as cURL include cookies?

Yes, Chrome includes session and persistent cookies in the -H 'Cookie: ...' header, provided they are sent with the request.

Why does the cURL command return different data than the browser?

Differences can arise from expired cookies, missing headers, or server-side user-agent detection. Ensure all headers and timing are consistent.

Is it safe to share copied cURL commands?

No—cURL commands may contain sensitive data like API keys or session tokens. Avoid sharing them publicly or storing them in plain text.

Can I use the cURL command in scripts?

Yes, but sanitize any embedded secrets and consider using environment variables for credentials instead of hardcoding them.

What if the request uses HTTP/2 or WebSocket?

cURL supports HTTP/2, but WebSocket connections cannot be replicated with cURL. The Network tab will only show standard HTTP requests.