Generate realistic browser user agent strings with options to filter by device type, browser family, and operating system. Perfect for web development testing and compatibility checks.
Generate random, realistic browser user agent strings for web development testing.
A User Agent string is a specific text identifier that web browsers and other applications send to websites to identify themselves. This string typically contains information about the browser, operating system, device type, and rendering engine being used. For web developers and testers, having access to a variety of realistic user agent strings is essential for testing website compatibility, responsiveness, and functionality across different platforms.
This Random User Agent Generator tool creates authentic-looking user agent strings based on your selected parameters. You can filter by device type (desktop or mobile), browser family (Chrome, Firefox, Safari, or Edge), and operating system to generate user agents that match your testing requirements. The tool provides a simple interface with options to copy the generated string with a single click and generate new random strings instantly.
User agent strings follow specific patterns depending on the browser and platform, but they generally contain several common components:
Here's a breakdown of typical user agent structures for major browsers:
1Mozilla/5.0 (platform; details) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/version Safari/537.36
2
1Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion
2
1Mozilla/5.0 (platform) AppleWebKit/webkitversion (KHTML, like Gecko) Version/safariversion Safari/safariversion
2
1Mozilla/5.0 (platform) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/chromiumversion Safari/537.36 Edg/edgeversion
2
The platform section varies significantly between desktop and mobile devices:
Desktop Examples:
Windows NT 10.0; Win64; x64
Macintosh; Intel Mac OS X 10_15_7
X11; Linux x86_64
Mobile Examples:
Linux; Android 12; SM-G998B
iPhone; CPU iPhone OS 15_4 like Mac OS X
Desktop user agents typically include specific operating system information, architecture details (like x86_64 or Win64), and sometimes language preferences. They tend to be more consistent across browsers than mobile user agents.
Mobile user agents contain device model information, mobile operating system versions, and often include the word "Mobile" at the end. Mobile Safari on iOS devices will include "iPhone" or "iPad" identifiers, while Android devices include the manufacturer and model number.
Each browser follows different versioning patterns:
Random user agent generation has several important applications in web development and testing:
Cross-Browser Compatibility Testing: Test how your website renders and functions across different browsers without needing to install multiple browsers or use multiple devices.
Responsive Design Testing: Verify that your website correctly detects mobile and desktop devices and serves the appropriate layout.
Feature Detection Validation: Ensure that your website's feature detection mechanisms work correctly for different browser capabilities.
QA and Automated Testing: Incorporate different user agents into your automated testing scripts to simulate various user environments.
Performance Testing: Analyze how your website performs when accessed from different browser environments.
Debugging Browser-Specific Issues: Reproduce and fix bugs that only occur in specific browsers or versions.
API Testing: Test how your API handles requests from different client applications.
While our random user agent generator is useful for many testing scenarios, there are alternative approaches:
Browser Testing Services: Platforms like BrowserStack, Sauce Labs, or LambdaTest provide actual browser instances for testing rather than just simulating the user agent.
Browser Developer Tools: Most modern browsers allow you to override the user agent through their developer tools, which can be useful for quick tests.
User Agent Switcher Extensions: Browser extensions that allow you to switch between predefined user agents while browsing.
Virtual Machines or Containers: Running actual instances of different operating systems and browsers for the most accurate testing.
Headless Browser Testing: Using tools like Puppeteer or Selenium to programmatically control browsers with different user agent settings.
Each alternative has its own advantages and may be more appropriate depending on your specific testing needs and resources.
The concept of the user agent string dates back to the early days of the World Wide Web. The term "user agent" comes from the HTTP specification, where it refers to the client application making a request to a web server.
The first widely used browser, NCSA Mosaic, included a simple user agent string that identified the browser name and version. When Netscape Navigator was released, it used a similar format. However, as web servers began to deliver different content based on the browser, a practice known as "browser sniffing" emerged.
During the browser wars between Netscape and Internet Explorer, websites often served optimized content exclusively to specific browsers. To ensure compatibility, browsers began to include strings that identified themselves as other browsers. This is why most modern browsers still include "Mozilla" in their user agent strings, a reference to Netscape Navigator's code name.
The rise of mobile devices introduced new complexity to user agent strings. Mobile browsers needed to identify themselves as mobile to receive appropriate content, leading to the addition of device identifiers and mobile-specific tokens.
As the web ecosystem has grown more complex, user agent strings have become increasingly convoluted. They now contain references to multiple browser engines (like "AppleWebKit" and "Gecko") for compatibility reasons, even when those engines aren't actually being used.
This complexity has led to challenges in accurately parsing user agent strings, and some web standards groups have proposed deprecating or simplifying user agent strings in favor of more structured client hints. However, for backward compatibility reasons, the traditional user agent string remains an essential part of web browsing.
Here are examples of how to work with user agent strings in various programming languages:
1// JavaScript: Detecting browser type from user agent
2function detectBrowser() {
3 const userAgent = navigator.userAgent;
4
5 if (userAgent.indexOf("Firefox") > -1) {
6 return "Firefox";
7 } else if (userAgent.indexOf("SamsungBrowser") > -1) {
8 return "Samsung Browser";
9 } else if (userAgent.indexOf("Opera") > -1 || userAgent.indexOf("OPR") > -1) {
10 return "Opera";
11 } else if (userAgent.indexOf("Trident") > -1) {
12 return "Internet Explorer";
13 } else if (userAgent.indexOf("Edge") > -1) {
14 return "Edge";
15 } else if (userAgent.indexOf("Chrome") > -1) {
16 return "Chrome";
17 } else if (userAgent.indexOf("Safari") > -1) {
18 return "Safari";
19 } else {
20 return "Unknown";
21 }
22}
23
24// Usage
25console.log("You are using: " + detectBrowser());
26
1# Python: Setting custom user agent in requests
2import requests
3
4def fetch_with_user_agent(url, user_agent):
5 headers = {
6 'User-Agent': user_agent
7 }
8 response = requests.get(url, headers=headers)
9 return response.text
10
11# Example usage
12chrome_ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
13content = fetch_with_user_agent('https://example.com', chrome_ua)
14print(content[:100]) # Print first 100 chars of response
15
1<?php
2// PHP: Detecting mobile devices using user agent
3function isMobileDevice() {
4 $userAgent = $_SERVER['HTTP_USER_AGENT'];
5 $mobileKeywords = array('Mobile', 'Android', 'iPhone', 'iPad', 'Windows Phone');
6
7 foreach ($mobileKeywords as $keyword) {
8 if (stripos($userAgent, $keyword) !== false) {
9 return true;
10 }
11 }
12 return false;
13}
14
15// Usage
16if (isMobileDevice()) {
17 echo "You are using a mobile device.";
18} else {
19 echo "You are using a desktop device.";
20}
21?>
22
1// Java: Generating a random user agent
2import java.util.Random;
3
4public class UserAgentGenerator {
5 private static final String[] CHROME_VERSIONS = {"96.0.4664.110", "95.0.4638.69", "94.0.4606.81"};
6 private static final String[] OS_VERSIONS = {"Windows NT 10.0; Win64; x64",
7 "Macintosh; Intel Mac OS X 10_15_7",
8 "X11; Linux x86_64"};
9
10 public static String generateRandomChromeUserAgent() {
11 Random random = new Random();
12 String osVersion = OS_VERSIONS[random.nextInt(OS_VERSIONS.length)];
13 String chromeVersion = CHROME_VERSIONS[random.nextInt(CHROME_VERSIONS.length)];
14
15 return "Mozilla/5.0 (" + osVersion + ") AppleWebKit/537.36 (KHTML, like Gecko) " +
16 "Chrome/" + chromeVersion + " Safari/537.36";
17 }
18
19 public static void main(String[] args) {
20 System.out.println(generateRandomChromeUserAgent());
21 }
22}
23
1# Ruby: Parsing user agent string
2require 'user_agent_parser'
3
4def parse_user_agent(user_agent_string)
5 parser = UserAgentParser::Parser.new
6 client = parser.parse(user_agent_string)
7
8 {
9 browser_name: client.family,
10 browser_version: client.version.to_s,
11 os_name: client.os.family,
12 os_version: client.os.version.to_s,
13 device: client.device.family
14 }
15end
16
17# Example usage
18ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1'
19info = parse_user_agent(ua)
20puts info
21
1// C#: Setting user agent in HttpClient
2using System;
3using System.Net.Http;
4using System.Threading.Tasks;
5
6class Program
7{
8 static async Task Main()
9 {
10 // Create HttpClient with custom user agent
11 using (var httpClient = new HttpClient())
12 {
13 string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36";
14 httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
15
16 try
17 {
18 // Make request with custom user agent
19 HttpResponseMessage response = await httpClient.GetAsync("https://example.com");
20 response.EnsureSuccessStatusCode();
21 string responseBody = await response.Content.ReadAsStringAsync();
22
23 Console.WriteLine($"Response received with status code: {response.StatusCode}");
24 Console.WriteLine(responseBody.Substring(0, 100) + "..."); // First 100 chars
25 }
26 catch (HttpRequestException e)
27 {
28 Console.WriteLine($"Request error: {e.Message}");
29 }
30 }
31 }
32}
33
1// Go: Creating HTTP requests with custom user agents
2package main
3
4import (
5 "fmt"
6 "io/ioutil"
7 "net/http"
8)
9
10func main() {
11 // Create a new request
12 req, err := http.NewRequest("GET", "https://example.com", nil)
13 if err != nil {
14 fmt.Printf("Error creating request: %s\n", err)
15 return
16 }
17
18 // Set custom user agent
19 req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")
20
21 // Send the request
22 client := &http.Client{}
23 resp, err := client.Do(req)
24 if err != nil {
25 fmt.Printf("Error sending request: %s\n", err)
26 return
27 }
28 defer resp.Body.Close()
29
30 // Read the response
31 body, err := ioutil.ReadAll(resp.Body)
32 if err != nil {
33 fmt.Printf("Error reading response: %s\n", err)
34 return
35 }
36
37 fmt.Printf("Response status: %s\n", resp.Status)
38 fmt.Printf("Response body preview: %s\n", body[:100])
39}
40
Here are some examples of real user agent strings for different browsers and platforms:
Chrome on Windows:
1Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
2
Firefox on macOS:
1Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0
2
Safari on macOS:
1Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15
2
Edge on Windows:
1Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62
2
Chrome on Android:
1Mozilla/5.0 (Linux; Android 12; SM-G998B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.104 Mobile Safari/537.36
2
Safari on iPhone:
1Mozilla/5.0 (iPhone; CPU iPhone OS 15_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Mobile/15E148 Safari/604.1
2
Firefox on Android:
1Mozilla/5.0 (Android 12; Mobile; rv:95.0) Gecko/95.0 Firefox/95.0
2
Samsung Internet on Galaxy:
1Mozilla/5.0 (Linux; Android 12; SM-G998B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/16.0 Chrome/92.0.4515.166 Mobile Safari/537.36
2
"User Agent." MDN Web Docs, Mozilla, https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
"Browser User Agent Strings." WhatIsMyBrowser.com, https://www.whatismybrowser.com/guides/the-latest-user-agent/
"HTTP User-Agent Header Explained." KeyCDN, https://www.keycdn.com/support/user-agent
"Client Hints." MDN Web Docs, Mozilla, https://developer.mozilla.org/en-US/docs/Web/HTTP/Client_hints
"History of the browser user-agent string." WebAIM, https://webaim.org/blog/user-agent-string-history/
"Browser Detection Using the User Agent." Google Developers, https://developer.chrome.com/docs/multidevice/user-agent/
Discover more tools that might be useful for your workflow