Extract Curl Requests from Safari on Mac, iPhone & iPad
In this article
This guide shows you how to capture the exact curl command for any network request made by Safari on macOS, iPhone, or iPad. This is useful for debugging APIs, replicating web actions in scripts, or inspecting what data a site sends and receives. You'll need a Mac (for the primary method) and the device you want to inspect. No additional software is required—everything uses built-in developer tools.
What You'll Need
- A Mac running macOS (any recent version).
- An iPhone or iPad (if you want to capture from those devices).
- A USB cable to connect your iPhone/iPad to the Mac (for iOS/iPadOS capture).
- Safari's Develop menu enabled (see Step 1).
Step-by-Step
On Mac (macOS Safari)
- Enable the Develop menu: Open Safari, go to Safari > Settings (or Preferences on older macOS), click the Advanced tab, and check “Show features for web developers”. Close the settings window.
- Open the Web Inspector: Navigate to the page you want to inspect. Right-click (or Control-click) on the page and select Inspect Element. Alternatively, press
Option+Command+I. - Go to the Network tab: In the Web Inspector panel that appears, click the Network tab at the top. The panel may be docked at the bottom or side; you can move it via the icon in the top-right of the inspector.
- Record network activity: Make sure the recording button (a circle) is red, indicating it's capturing. If not, click it to start. Then reload the page or perform the action you want to capture (e.g., clicking a button that sends a request).
- Find the request: A list of network requests will appear. Click on the one you're interested in—usually the one with a name matching the API endpoint or resource you want. You can filter by type (e.g., XHR/Fetch) using the filter bar at the top.
- Copy as cURL: With the request selected, look at the right-side details panel. Find the Headers section. At the top of that section, you'll see a “Copy as cURL” button (sometimes a small icon that looks like a terminal). Click it. The
curlcommand is now copied to your clipboard. - Use the curl command: Paste it into a terminal and run it. It will reproduce the exact request, including headers, cookies, and body data.
On iPhone or iPad (via Mac)
- Connect your device: Use a USB cable to connect your iPhone or iPad to your Mac. If prompted, trust the computer on your device.
- Enable Develop menu on Mac (if not already): Follow Step 1 from the Mac section.
- Open the Develop menu: In Safari on your Mac, click the Develop menu in the top menu bar. You should see your iPhone/iPad listed under the “Devices” submenu. If not, make sure your device is unlocked and Safari is open on it.
- Open Web Inspector for the device: Hover over your device name, and a list of open Safari tabs will appear. Click the tab you want to inspect. A Web Inspector window will open on your Mac, showing the page from your device.
- Follow the same steps as Mac: In the Web Inspector, go to the Network tab, reload or interact with the page on your iPhone/iPad, find the request, and click “Copy as cURL”.
Note: For iOS/iPadOS, the Web Inspector only works over USB, not Wi-Fi, and requires the device to be trusted.
Common Mistakes
- Not enabling the Develop menu: If you can't see the Develop menu or Inspect Element, you missed Step 1.
- Looking at the wrong request: Many pages load dozens of resources (images, scripts). Make sure you select the actual API call you need—often those with a JSON response or a path like
/api/. - Copying before the request completes: If you copy a request that is still loading, the curl command may be incomplete. Wait for the request to finish (the status turns from “pending” to a number like 200).
- Forgetting to reload: If you don't reload or trigger the action, the network tab will be empty. Always refresh the page or perform the user action after opening the Network tab.
- Using the wrong device in Develop menu: On iPhone/iPad, make sure you select the correct tab from the device list. If you have multiple tabs open, you might inspect the wrong one.
Tips
- Filter by type: Use the filter bar (e.g., “XHR” or “Fetch”) to quickly narrow down to API requests, avoiding images and CSS.
- Clear the log first: Click the trash icon in the Network tab to clear previous entries before you start, so you only see the request you care about.
- Use the “Preserve log” option: If the page redirects, you might lose requests. Enable “Preserve log” (a checkbox in the Network tab) to keep all requests even after navigation.
- Copy as cURL includes cookies: The command will include your session cookies, so it will work only as long as those cookies are valid. Be aware that sharing the command can expose your session.
- For POST requests with a body: The curl command will include a
--dataor--data-rawflag. If the body is large, you may want to save it to a file for readability.
Troubleshooting
- No Develop menu appears: Go to Safari > Settings > Advanced and ensure “Show features for web developers” is checked. If it still doesn't appear, restart Safari.
- iPhone/iPad not showing in Develop menu: Unlock the device, keep Safari open, and make sure you've tapped “Trust” on the device when prompted. Try disconnecting and reconnecting the cable. Also check that your Mac has the latest macOS updates.
- Network tab is empty: Click the record button (red circle) to ensure it's on. Then reload the page. If you're on a page that uses a service worker, you might need to disable “Disable caches” (a checkbox in the Network tab) to see all requests.
- “Copy as cURL” is greyed out: This happens if the request is still loading or if you've selected a resource that hasn't loaded. Wait for the request to complete, or click on a different request.
- curl command fails when run: This often happens because the request requires a valid session or token that has expired. Re-copy the curl command right after performing the action, and run it immediately. Also, ensure you're running it in a terminal with network access.
Frequently Asked Questions
Can I capture requests from Safari on iPhone without a Mac?
No. The built-in Web Inspector requires a Mac with the Develop menu. There is no way to extract curl directly from iOS Safari without a Mac.
Does this work with other browsers like Chrome or Firefox?
This guide is specific to Safari. Chrome and Firefox have their own developer tools with similar “Copy as cURL” features, but the steps differ.
Will the curl command include my login session?
Yes, it will include cookies and headers that are part of the request, which often contain session tokens. Be careful not to share it publicly.
Can I use this to capture HTTPS requests?
Yes. The Web Inspector captures the request as sent, including HTTPS. The curl command will include the necessary TLS parameters automatically.
What if the request uses WebSocket?
The Network tab shows WebSocket connections, but “Copy as cURL” does not work for WebSocket handshakes. You'll need to manually capture the handshake URL and headers.
Is there a way to capture requests from a specific app on iPhone, not Safari?
No. This method only works for Safari web traffic. For other apps, you'd need a proxy tool like Charles or mitmproxy, which is beyond this guide's scope.