User Agents

Web browsers and everyday web tech, explained

Extract curl Requests from Firefox: Step-by-Step Guide

· 6 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 curl requests from Firefox allows you to capture a specific HTTP request made by your browser and replicate it exactly in a command-line interface or an API testing tool. This process is essential for developers, security researchers, and QA engineers who need to debug API calls, analyze headers, or automate interactions with a web server without manually reconstructing the request parameters. By using the built-in Developer Tools, you can export the full request—including cookies, authentication tokens, and POST data—into a single curl command that can be executed in any terminal.

What You'll Need

  • A computer with the Mozilla Firefox browser installed.
  • A terminal or command-line interface (such as Bash on Linux/macOS, PowerShell or CMD on Windows) to run the extracted curl command.
  • The specific website or web application you wish to analyze open in a tab.

Step-by-Step

  1. Open Firefox Developer Tools: Launch Firefox and navigate to the page where the network request occurs. To open the Developer Tools, you can right-click anywhere on the page and select "Inspect" from the context menu, or use the keyboard shortcut Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (macOS).
  2. Navigate to the Network Tab: Once the Developer Tools panel opens (usually at the bottom or side of the screen), look at the top navigation bar of the toolset. Click on the "Network" tab. This tab monitors every single request the browser sends to a server and every response it receives.
  3. Trigger the Request: If the Network tab is empty, you need to perform the action on the website that triggers the request you want to capture. This could be clicking a "Submit" button on a form, refreshing the page, or interacting with a dynamic element that loads data via AJAX. As you interact with the page, you will see a list of entries appearing in the Network panel.
  4. Filter the Results: Large websites often load dozens of images, scripts, and CSS files, which can clutter the list. To find your specific request, use the filter bar at the top of the Network tab. For example, if you are looking for an API call, click the "XHR" or "Fetch" filter button. This hides static assets and shows only the asynchronous data requests.
  5. Identify the Correct Request: Scan the "File" column for the name of the endpoint or the URL that matches the action you performed. You can click on an entry to see more details in the right-hand pane, such as the request headers, the payload (for POST requests), and the response body.
  6. Copy as curl: Once you have found the correct request, right-click on the name of the file/request in the list. Hover over the "Copy Value" menu item, and then select "Copy as curl". Depending on your operating system, you may see options like "Copy as curl (bash)" or "Copy as curl (cmd)". Choose the one that matches the terminal environment where you intend to run the command.
  7. Paste and Execute: Open your terminal application. Paste the copied command into the prompt. The command will be quite long because it includes all the headers (like User-Agent and Cookie) and the data payload. Press Enter to execute the request.

Common Mistakes

One of the most frequent errors is failing to keep the Network tab open before performing the action on the website. Firefox only records network activity that occurs while the Developer Tools are active. If you refresh the page or click a button and then open the Network tab, the initial request will be missing. Always ensure the tools are open and the Network tab is selected before triggering the event.

Another common mistake is copying the request for a static asset (like a .png or .js file) instead of the actual API endpoint. Users often see a long list of files and pick the first one they see. Always check the "Type" column or use the XHR/Fetch filters to ensure you are capturing the data exchange rather than a layout file.

Users also frequently forget to account for session expiration. A curl request captured from Firefox includes the current session cookies. If you wait too long to run the curl command in your terminal, the session on the server may expire, resulting in a 401 Unauthorized or 403 Forbidden error, even though the command was copied correctly.

Tips

To make the extracted curl command more readable or reusable, you can paste it into a text editor first. This allows you to remove unnecessary headers that the server might ignore, such as sec-ch-ua-platform or upgrade-insecure-requests, making the command shorter and easier to manage.

If you are dealing with a request that sends a large amount of JSON data, the curl command will be massive. In these cases, consider saving the data payload to a separate file (e.g., data.json) and modifying the curl command to use the -d @data.json flag. This keeps your terminal clean and prevents issues with shell character escaping.

For those who need to modify the request before sending it, importing the curl command into a tool like Postman or Insomnia is highly recommended. Most modern API clients have an "Import" feature where you can paste a raw curl command, and the tool will automatically parse it into a GUI format, allowing you to change parameters or headers without editing a long string of text.

Troubleshooting

The curl command returns a 403 Forbidden error: This is usually caused by a missing or expired cookie or a CSRF (Cross-Site Request Forgery) token. Check if the website requires a fresh login. If it does, log in again, trigger the request, and copy the curl command immediately. Some servers also check the Referer or Origin headers; ensure these were captured in the copy process.

The command fails with a "command not found" error: This means curl is not installed on your system. While macOS and most Linux distributions come with curl pre-installed, some Windows versions do not. You can download curl from the official website or use a package manager like Chocolatey or Winget to install it.

Special characters are causing syntax errors in the terminal: When copying for Windows CMD, some characters (like single quotes) may not be handled the same way as in Bash. Ensure you selected "Copy as curl (cmd)" specifically. If you are using PowerShell, you may need to wrap the entire command in a different way or use the bash-style copy and run it within a WSL (Windows Subsystem for Linux) environment.

The response in the terminal is a mess of HTML: This happens when the request is successful, but the server returns a full HTML page instead of JSON. This is common if the request was redirected to a login page. Check the response code in the terminal (using -i in your curl command to see headers) to see if you were redirected (301 or 302 status codes).

Frequently Asked Questions

Does copying as curl include my password?

It does not include your plaintext password, but it does include your session cookies and authentication tokens. Anyone with this curl command can impersonate your session until the token expires.

Can I use this to bypass a login screen?

No. The curl command replicates a request that was already authorized. It does not grant access to a site without a valid, active session token or cookie.

What is the difference between Copy as curl (bash) and (cmd)?

The primary difference is the quoting convention. Bash uses single quotes for strings, while Windows CMD uses double quotes. Choosing the wrong one will lead to syntax errors in your terminal.

Why is the curl command so long?

Firefox copies every single header the browser sends to ensure the server cannot distinguish the curl request from a real browser request. This includes browser version, language settings, and security policies.

Can I use this method for HTTPS sites?

Yes, curl handles HTTPS by default. If you encounter SSL certificate issues on a local development environment, you can add the -k or --insecure flag to the command to ignore certificate validation.