Learning center

Browser or server? Replay the failing request outside the page

To tell a page bug from a server bug, send the failing request from outside the browser. The same bad response means the server produced it, and a good one points at the browser or the page.

Why a replay decides it#

A browser request carries the page's cookies, headers and body. The response then passes through the page's code before anything appears on screen. A failure on screen can come from any of those steps. Replaying the request with curl removes the page from the picture: same URL, same headers, same body, no JavaScript.

Replay resultWhat it establishesWhere to look next
Same status and body as in the browserThe server returned this answer for this requestServer logs, the request's inputs, recent deploys
Works in curl, fails in the browserSomething only the browser applies changes the outcome, or the server's answer changed between attemptsRetry in the browser right after the replay; if it still fails, CORS, cookies, extensions, the service worker, page code
Different but also wrongThe request depends on state that changed between attemptsSession expiry, caches, rate limits; record both times

A replay keeps the headers and body the page generated and removes only the page's code. When the same bad response comes back, the server produced it, but the request may still carry a wrong input from the page. Compare it with a request that works before you assign the bug to the server's logic.

Copy the request#

In Chrome's Network panel, right-click the request and choose Copy > Copy as cURL. The command includes the method, URL, headers and body the browser sent. Copy as fetch gives the same request as JavaScript, which you can paste into the Console of a fresh tab on the same site. Copy options

The copied command includes the Cookie and Authorization headers. Treat it like a password: run it yourself, and before you paste it into a ticket or chat, replace those values with placeholders such as COOKIE_VALUE. Anyone holding the original can act as you until the session ends.

Add -i so curl prints the status line and response headers, and -o body.txt if the body is large.

curl -i 'https://app.example.test/api/invoices/INV-2041/pdf' \
  -H 'Accept: application/pdf' \
  -H 'Cookie: session=COOKIE_VALUE'

Worked example: a PDF download that fails for one invoice#

This example is fictional. A user reports that Download PDF shows a short error text instead of a PDF for one invoice and works for all others. The Network panel shows 200 for the failing download, with Content-Type: application/json and a body of {"error":"template_missing"}.

Two causes fit. The server could be returning an error with the wrong status (Cause A, a server bug), or the page could be sending something different for this invoice, such as a stale header or query parameter from a cached page (Cause B, a client bug).

The curl replay returned the same 200 with the same JSON body. That shows the server answered this request this way, but the replay carried every header the page sent, so it does not yet rule out Cause B. Copying the request for a working invoice as cURL showed the same headers and parameters, apart from the invoice ID, and replaying the failing request with the working one's headers returned the same JSON. That rules out Cause B. The report said: for INV-2041, the PDF endpoint returns 200 with {"error":"template_missing"} and Content-Type: application/json, both in the browser and in a curl replay at 14:05 UTC. The browser displays the JSON body in the new tab, because no PDF came back. The fix had two parts: return a 4xx or 5xx status for this error, and make the page show it.

When the replay works#

If curl gets the right answer, compare what the browser sent with what you replayed. These are the usual differences:

  • CORS. curl does not enforce it. See the CORS guide.
  • Cookies the browser did not send. The copied command contains the cookies the browser actually sent. Replay without cookies to see whether the endpoint depends on them, and see the cookie guide.
  • A service worker or cache. The browser may never have reached the server. The Network panel's timing tab shows when a service worker answered. See the old version guide.
  • The page's own code. The response is fine and the page mishandles it. Look at the Console at the moment the response arrived.

Replay with care#

A replay is a real request. Replaying a POST that creates an order creates another order. Before replaying a write, use a test account or a staging environment, or replay only the GET that shows the state. Write the replay's time in the report, so the receiver does not mistake it for a user action in the server logs.

What to put in the report#

  • The request as a curl command, with credentials replaced by placeholders.
  • The status line, the headers that matter, and the first lines of the body for the browser attempt and the replay.
  • The time of each attempt, in UTC.
  • Which result you got: same as browser, works outside the browser, or different.

Questions#

Can I replay a request that needs a CSRF token?

Copy as cURL includes the token the browser sent, if it was in a header or the body. The token may expire with the session, so replay soon after copying. If the server rejects the replay with a CSRF error, say so in the report; it does not show the original failure.

Should I use Postman or another client instead of curl?

Any client that sends exactly the copied request works. curl is useful in a report because the command itself documents the request, and the receiver can run it.

What if the request uses HTTP/2 or a WebSocket?

Most curl builds negotiate HTTP/2 over HTTPS when the server offers it, and --http1.1 forces the older protocol if you need to compare. A WebSocket conversation is not a single request; record the messages around the failure from the request's Messages tab instead. WebSocket messages

Return to the method for browser bug reports for the other symptoms in this collection.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading