Glossary
User agent spoofing: changing the name your client gives
User agent spoofing is the practice of replacing a client's real User-Agent string with another one, usually to look like a common desktop or mobile browser.
Definition
Every HTTP client lets you set request headers, and the User-Agent is just another header. Spoofing it means sending a value that does not describe the software actually making the request: a Python script claiming to be Chrome, a Linux server claiming to be an iPhone, or a desktop browser emulating a tablet for layout testing.
The word "spoofing" sounds sinister, but the practice is everyday. Browser developer tools include a device emulator that changes the User-Agent, and QA teams use it constantly to test responsive layouts.
Setting it in common tools
# Python httpx
import httpx
ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
with httpx.Client(headers={"User-Agent": ua}, timeout=30) as http:
page = http.get("https://example.com/catalog")
In Playwright you set userAgent when creating a browser context; in Selenium you pass a --user-agent= argument to Chrome options; in curl you use -A. Each changes the header, and in browsers also the value of navigator.userAgent.
What a spoofed value fails to change
The header is the easy part. A site that cares compares it with signals the header does not control:
- TLS handshake: the TLS fingerprint still names your real library.
- HTTP/2 settings and header order: still those of your client.
- Client hints: browsers send
Sec-CH-UAheaders that may still describe the real version or platform. - JavaScript properties:
navigator.platform, fonts, screen size and GPU strings describe the real machine. - Feature support: claiming a newer browser than you run exposes missing APIs.
When these disagree, the site sees a mismatched user agent, which is usually a stronger bot signal than an honest library string would have been.
Legitimate reasons to spoof
Besides layout testing, teams change the string to see how a site treats different devices, to reproduce a bug a customer reported from a specific browser, or because a target serves an error page to anything that announces itself as a script library. Monitoring a public page with a realistic header is common and generally harmless when the request rate stays modest.
Spoofing well, when you must
Claim something close to the truth
If your automation runs Chrome on Linux, claim Chrome on Linux with the same major version. The smaller the gap between claim and reality, the fewer signals you need to adjust.
Change the layers together
For HTTP clients, choose one that can reproduce the TLS and HTTP/2 behavior of the browser you name. For browsers, set the matching client hints and keep viewport and locale consistent with the device type.
Rotate per session, not per request
A real person does not switch browsers between page two and page three. Pick a value when a session starts and keep it with its cookies.
Spoofing and CAPTCHA answers
A spoofed string interacts with challenge answers. For a Cloudflare Challenge or DataDome Slider task you pass the User-Agent you will use, and the returned cookie is valid only together with it, from the same proxy. For token tasks like reCAPTCHA v3, GateSolver returns the User-Agent it used; sending that one when you submit the token avoids a mismatch the site may check. Changing your string between solving and submitting is a frequent cause of rejected answers, explained further in why a token is rejected.
Spoofing is fine for testing layouts, monitoring public pages and similar work. Using it to impersonate users for fraud is not an allowed use of any part of our service.
Common questions
Is user agent spoofing illegal?
Changing a header is not illegal in itself; legality depends on what the automation does and on the site's terms and local law.
Why is my spoofed Chrome string still blocked?
Other signals such as the TLS handshake, client hints and JavaScript properties still describe your real client.
Should I use a random user agent for every request?
No. Keep one per session; changing it between requests breaks session continuity and stands out.
Does a spoofed user agent affect cf_clearance cookies?
Yes. The cookie is tied to the User-Agent sent when it was issued, so later requests must send the same string.
Can I spoof the user agent in a headless browser?
Yes, through the context or launch options, which also updates navigator.userAgent inside pages.
Keep reading
- User agentThe User-Agent header, how a Chrome string is put together, and how client hints now carry part of the same data.
- Mismatched user agentWhen the header, client hints, TLS handshake and in-page JavaScript describe different browsers, and why that draws challenges.
- Change the user agent in SeleniumSet a custom user agent in Selenium through Chrome options or a CDP override, and keep client hints telling the same story.
- Why does the site reject my solved token?Rejected tokens usually trace back to a wrong site key, stale timing, a missing action or a mismatched browser session.