What Is a User Agent in a Browser?
A browser user agent is the software making a web request; its User-Agent string describes the client but cannot reliably prove its identity or capabilities.
A browser user agent is the browser software acting as a client when it requests a web resource. In everyday web development, “user agent” also often means the User-Agent HTTP request header or the corresponding navigator.userAgent JavaScript property. The string can advertise browser, operating-system, vendor, and version details, but it is not reliable proof of identity or capability.
The term can also describe non-browser clients, such as a crawler or command-line HTTP library. A user-agent string is the identifying text those clients send; context tells you which meaning is intended.
What does a user agent tell a website?
When a client makes an HTTP request, it may include a User-Agent header. A server can inspect that header for diagnostics, coarse analytics, or compatibility handling. In browser JavaScript, a page can read the browser-provided value with navigator.userAgent.
// In a browser console
console.log(navigator.userAgent);
A typical legacy string follows a convention that includes a product identifier and version, sometimes with comments containing platform information. In practice, many strings include compatibility tokens associated with other browsers, so they are not a clean inventory of every component. See MDN’s reference for the [User-Agent HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) and the [`navigator.userAgent` property](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgent).
Both the header and the JavaScript property are advertised values. A client can change them, browsers can reduce details, and different clients can use similar strings. Treat them as clues, not authentication credentials or guaranteed facts.
How to find a browser user agent
- In browser JavaScript: open the developer console and run
navigator.userAgent. - On a server: inspect the incoming request’s
User-Agentheader. Header access syntax depends on your server framework. - For a command-line request: send an HTTP request and inspect the request headers using your HTTP client’s verbose or trace option. The client itself may send a user-agent value.
For example, this browser snippet checks whether the property is available and prints it:
if (typeof navigator !== "undefined" && "userAgent" in navigator) {
console.log(navigator.userAgent);
} else {
console.log("No browser user-agent property is available");
}
The string is often useful when recording a bug report, but include other diagnostic details too: the actual error, the feature involved, and the operating environment the user reports. Do not assume the string uniquely identifies a person or device.
Why user-agent sniffing is unreliable
Checking for a browser name or version and using that as a proxy for feature support is called user-agent sniffing. It is a poor default because browser strings contain compatibility tokens, can be modified, and change over time. A version number does not directly answer whether the exact API or behavior your code needs is available. MDN documents these pitfalls in its guide to [browser detection using the user-agent string](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Browser_detection_using_the_user_agent).
When the question is “Can this browser do this?”, test the capability itself and provide a fallback or progressively enhance the experience.
// Capability check: test the method you need
if ("IntersectionObserver" in window) {
// Use IntersectionObserver
} else {
// Use a suitable fallback
}
If a browser-specific workaround is genuinely necessary, keep it narrow, document the specific bug it handles, and avoid treating the user-agent string as a capability contract.
User-Agent Client Hints and privacy
Detailed browser and platform information can contribute to fingerprinting. In supporting browsers, user-agent reduction removes or normalizes some details from the legacy string, such as exact operating-system versions, device models, and minor browser version components. Reduction limits particular details; it does not guarantee anonymity. MDN explains the rationale and behavior in its [User-Agent reduction overview](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/User-agent_reduction).
User-Agent Client Hints provide a more selective way for a server to request some browser or platform information. A server can advertise accepted hints with Accept-CH; subsequent requests in supporting implementations may include Sec-CH-UA-* headers. In JavaScript, navigator.userAgentData exposes low-entropy data, and getHighEntropyValues() can request selected additional values where supported. Availability varies, and the API requires a secure context in some or all supporting browsers. Check current compatibility before depending on it. See MDN’s [`userAgentData` property](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgentData) and [`NavigatorUAData`](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData).
// Gracefully handle browsers without User-Agent Client Hints
if (navigator.userAgentData) {
console.log(navigator.userAgentData.brands);
// Request only details you have a legitimate need to use.
navigator.userAgentData.getHighEntropyValues(["platformVersion"])
.then((details) => console.log(details))
.catch(() => console.log("Additional hints unavailable"));
} else {
console.log("User-Agent Client Hints are unavailable here");
}
Request and retain only the details your application needs. Client Hints do not remove the need to consider compatibility and data minimization.
Legacy User-Agent string, Client Hints, and feature detection
| Approach | Useful for | Tradeoff |
|---|---|---|
| Legacy User-Agent string | Diagnostics and coarse request logging | Can be misleading, changed, reduced, and identifying |
| User-Agent Client Hints | Selectively requesting browser or platform details | Support varies; additional values may need to be requested |
| Feature detection | Deciding whether a specific API or capability is available | Requires testing the behavior or API your code actually needs |
For feature decisions, feature detection is usually the direct answer. Use the user-agent string when the user-agent value itself is relevant, such as recording diagnostic context, and handle it as untrusted input.
Or skip the browser setup
If your task is to capture a page rather than inspect its user-agent string, ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
- Cookie banners, newsletter popups, and chat widgets are removed before the shot; each cleanup step can be turned off.
- Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and billing status.
- An MCP server lets AI agents use
take_screenshot,get_page_info, andcapture_pdf. - 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000 screenshots.
Sign up free for 1,000 screenshots a month, with no card required.
Troubleshooting user-agent checks
The browser name check says a feature is supported, but it fails
Cause: A name or version token is only an indirect hint, and compatibility tokens can make string checks match clients that do not support the expected behavior.
Fix: Check the API or behavior directly and provide a fallback.
navigator.userAgentData is undefined
Cause: The browser or execution context may not support the API; support and secure-context requirements vary.
Fix: Feature-detect the property, check current compatibility, and avoid requiring the data if it is not essential.
The user-agent string does not show the device or exact version
Cause: Supporting browsers may reduce or normalize some details, and clients can alter the header.
Fix: Do not treat absent detail as an error or infer a precise device from the value. If there is a legitimate need, consider requesting only the relevant Client Hint where supported.
A server-side user-agent value looks unexpected
Cause: Requests can come from crawlers, command-line libraries, or other software, and any client can send a chosen header value.
Fix: Treat the header as untrusted metadata. Do not use it for authentication, authorization, or security decisions.
Performance, reliability, and cost considerations
Reading navigator.userAgent is a local property access; sending the value to a server, storing it, or acting on it creates the meaningful operational and privacy choices. Avoid collecting it without a clear diagnostic or product need. If you use a request header or Client Hint to vary responses, account for the resulting cache behavior and verify that the selected information is available on the requests where it is needed. Do not make core functionality depend on a browser-identification guess.
FAQ
Is a user agent the same as a browser?
No. The user agent is the software making a request, which may be a browser, crawler, or HTTP client. “User-agent string” refers to the text identifier sent with a request or exposed by a browser API.
Can a website identify me from my user agent?
The string can reveal some client details and may contribute to fingerprinting, but it is not a unique or guaranteed identity. Browsers can reduce details, and clients can change the value.
Should I block a request based on its user agent?
A user-agent string is easy for a client to choose, so it is not a trustworthy basis for access control. Use appropriate authentication and server-side security checks for protected resources.
Is navigator.platform a better browser detector?
Not as a general feature detector. Platform values also vary and should not substitute for checking whether the capability your code needs is available. See MDN’s [`navigator.platform` reference](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform).


