Skip to content

Site Works in Browser but Fails in JMeter

Fix the classic JMeter problem: requests work in a browser but fail in JMeter. Missing headers, cookies, redirects, correlation, and JavaScript gaps.

Difficulty
intermediate
Guide type
troubleshooting
Estimated read time
7 min read
Last verified version
Verified JMeter 5.6

The application works perfectly in a browser, but the same requests in JMeter fail with:

Response code: 401 / 403 / 404 / 500

empty response bodies, redirects that never land, or assertion failures. Recorded scripts replay once and then fail on every subsequent run.

Browsers do far more than send the URL: they attach a full header set, manage cookies, follow redirects, execute JavaScript that fires extra requests, and carry fresh dynamic tokens. A replayed JMeter script does none of that automatically. Find which of these the failing request depends on and add it explicitly.

CauseTypical ErrorWhy it happens
Missing request headers403 or 400The server or WAF checks User-Agent, Accept, Origin, or custom headers the browser sends but the script omits
No Cookie Manager401 or lost sessionSessions ride cookies; without a Cookie Manager each request arrives stateless
Uncorrelated dynamic values401, 403, 400CSRF tokens, session IDs, or bearer tokens from the recording are stale
Redirect handling mismatchRedirect loops or 302 chainsFollow Redirects and Redirect Automatically behave differently, and one is often disabled
JavaScript-driven flowsMissing requests entirelySPAs fire API calls from JavaScript, which JMeter never executes
URL encoding differences400 or 404Special characters in parameters encode differently between browser and sampler

1. Compare the failing request with browser DevTools

Section titled “1. Compare the failing request with browser DevTools”

Open the browser’s Network tab, perform the action manually, and inspect the successful request. Compare, field by field against the JMeter sampler:

  1. Request headers (especially User-Agent, Accept, Content-Type, Origin, and any custom security headers).
  2. Cookies sent with the request.
  3. Query and body parameters, including tokens.
  4. The exact URL and encoding.

Add the missing pieces to the sampler, then re-run one thread.

2. Add missing headers with an HTTP Header Manager

Section titled “2. Add missing headers with an HTTP Header Manager”

Add an HTTP Header Manager at the test plan or thread group level for global headers, or under a single sampler for request-specific ones. Replicate only what the server actually inspects; there is no need to copy every browser header.

Sessions break without one. Add an HTTP Cookie Manager to each thread group. Keep the default “clear cookies each iteration” behavior unless the scenario explicitly models a returning user with a persistent session.

Extract tokens from the response that provides them and pass them into the next request:

  1. Locate the token in the login or page-load response (CSRF field, session ID, bearer token).
  2. Add a Regular Expression Extractor or JSON Extractor for it.
  3. Reference the variable in the failing request.

The Correlation & Dynamic Values guide covers the patterns in depth, and HTTP 401/403 after recording covers the auth-specific variants.

In the sampler, Follow Redirects (HttpClient implementation) hands redirects to JMeter’s logic and records the final response, while Redirect Automatically replays them at the protocol level with fewer hooks. Enable exactly one per sampler, never both, and inspect the redirect chain in DevTools to know how many hops to expect.

JMeter does not execute JavaScript. For SPA flows:

  1. Watch the Network tab while the page runs and list the real API calls behind the UI action.
  2. Script those calls directly as HTTP Requests in the right order.
  3. Replace browser-only behavior (token refresh, polling) with its HTTP equivalent.

API Load Testing shows how to structure these protocol-level tests.

ResourceUse when
HTTP 401/403 after recordingAuth failures dominate the replay
Correlation & Dynamic ValuesTokens and session IDs need extraction
HTTP RecorderCapturing browser traffic cleanly in the first place
Extractor Default ValueExtractors return NOT_FOUND during correlation

Why does JMeter not execute JavaScript like a browser?

Section titled “Why does JMeter not execute JavaScript like a browser?”

JMeter is a protocol-level tool: it sends and receives HTTP requests without rendering pages or running scripts. Any request a browser fires from JavaScript must be discovered in DevTools and scripted as an explicit HTTP Request.

Which browser headers does JMeter actually need?

Section titled “Which browser headers does JMeter actually need?”

Only the ones the server or WAF inspects. Start with User-Agent, Accept, Content-Type, and any custom security or anti-bot headers visible in DevTools, then add more only while failures persist.

Why does my recorded script fail on the second run?

Section titled “Why does my recorded script fail on the second run?”

Recording captures tokens and cookies that expire after the first use. Add a Cookie Manager and correlate CSRF tokens, session IDs, and bearer values so each virtual user gets fresh ones.

Can JMeter test a single-page application?

Section titled “Can JMeter test a single-page application?”

Yes, but at the API level. Identify the HTTP calls the SPA makes behind its UI, script them in order, and treat the browser as a reference for the request sequence rather than as something to emulate.

On this page