User Agent Parser

Analyze and parse user agent strings to extract detailed information about browsers, engines, operating systems, CPU architecture, and devices.

User Agent String

Your current user agent is automatically loaded. Modify it or paste a different one to analyze.

Browser

-

-

-

Engine

-

-

Operating System

-

-

Device

-

-

-

CPU

-

What is a User Agent string?

A User Agent string is a piece of text that web browsers and other applications send to web servers to identify themselves. It contains information about the browser, version, operating system, device, and rendering engine. Web servers use this information to serve appropriate content and optimize the user experience.

User Agent strings follow a standardized format but can vary significantly between different browsers and devices. They're essential for web development, testing, and analytics to understand what browsers and devices are accessing websites.

How to get User Agent in Selenium WebDriver?

You can retrieve the User Agent string in Selenium WebDriver using JavaScript execution:

Python (Selenium)

from selenium import webdriver

driver = webdriver.Chrome()
user_agent = driver.execute_script("return navigator.userAgent;")
print(f"User Agent: {user_agent}")

# You can also set a custom user agent
options = webdriver.ChromeOptions()
options.add_argument("--user-agent=Custom User Agent String")
driver = webdriver.Chrome(options=options)

Java (Selenium)

WebDriver driver = new ChromeDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
String userAgent = (String) js.executeScript("return navigator.userAgent;");
System.out.println("User Agent: " + userAgent);

// Setting custom user agent
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent=Custom User Agent String");
WebDriver driver = new ChromeDriver(options);

How to get User Agent in Puppeteer?

Puppeteer provides several ways to work with User Agent strings:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  
  // Get current user agent
  const userAgent = await page.evaluate(() => navigator.userAgent);
  console.log('Current User Agent:', userAgent);
  
  // Set a custom user agent
  await page.setUserAgent('Mozilla/5.0 (Custom Browser) AppleWebKit/537.36');
  
  // Verify the new user agent
  const newUserAgent = await page.evaluate(() => navigator.userAgent);
  console.log('New User Agent:', newUserAgent);
  
  await browser.close();
})();

How to get User Agent in Playwright?

Playwright offers built-in methods for User Agent management:

JavaScript/TypeScript

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext({
    userAgent: 'Mozilla/5.0 (Custom Playwright Browser)'
  });
  
  const page = await context.newPage();
  
  // Get current user agent
  const userAgent = await page.evaluate(() => navigator.userAgent);
  console.log('User Agent:', userAgent);
  
  await browser.close();
})();

Python

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    context = browser.new_context(
        user_agent="Mozilla/5.0 (Custom Playwright Browser)"
    )
    
    page = context.new_page()
    user_agent = page.evaluate("() => navigator.userAgent")
    print(f"User Agent: {user_agent}")
    
    browser.close()

Why do User Agent strings matter for testing?

User Agent strings are crucial for comprehensive web testing:

  • Browser Compatibility Testing - Verify your site works across different browsers and versions
  • Responsive Design Testing - Test mobile vs desktop layouts and behaviors
  • Feature Detection - Ensure proper fallbacks for unsupported features
  • Analytics Validation - Verify correct tracking and segmentation
  • A/B Testing - Test different experiences for different user segments
  • Security Testing - Test how your application handles various clients
  • Performance Testing - Optimize loading for different device capabilities

By parsing and analyzing User Agent strings, you can create more targeted tests and ensure your application provides optimal experiences across all platforms.