Browser Detection API: The Complete Guide

Need to identify which browser your users are using? This guide covers everything you need to know about browser detection via API, including version identification, engine detection, and implementation examples.

What is Browser Detection?

Browser detection is the process of identifying the web browser being used to access your application. This includes the browser name, version number, and rendering engine. This information helps provide browser-specific fixes or features.

Modern browsers include Chrome, Firefox, Safari, Edge, and many others, each with their own quirks and capabilities.

Major Browsers

The most common browsers and their engines:

Browser Engine Platform
ChromeBlinkCross-platform
FirefoxGeckoCross-platform
SafariWebKitmacOS, iOS
EdgeBlinkCross-platform
OperaBlinkCross-platform
Samsung InternetBlinkAndroid
Pro Tip: Feature detection is generally preferred over browser detection. Use browser detection only when you need to work around known browser bugs.

Using the Browser Detection API

TinyFn provides an endpoint to detect browser information:

API Request
POST https://api.tinyfn.io/v1/detect/browser
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
Response
{
  "browser": {
    "name": "Chrome",
    "version": "120.0.0.0",
    "major_version": 120,
    "minor_version": 0
  },
  "engine": {
    "name": "Blink",
    "version": "120.0.0.0"
  },
  "is_chromium": true,
  "is_modern": true,
  "supports": {
    "webgl": true,
    "webp": true,
    "avif": true,
    "css_grid": true,
    "es6": true
  }
}

Parameters

Parameter Type Description
user_agent string User agent string (required)
include_support boolean Include feature support info (default: true)

Code Examples

JavaScript / Node.js

const response = await fetch('https://api.tinyfn.io/v1/detect/browser', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your-api-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    user_agent: navigator.userAgent
  })
});
const data = await response.json();

console.log(`Browser: ${data.browser.name} v${data.browser.major_version}`);

// Apply browser-specific fixes
if (data.browser.name === 'Safari' && data.browser.major_version < 15) {
  applySafariFix();
}

Python

import requests

def detect_browser(user_agent):
    response = requests.post(
        'https://api.tinyfn.io/v1/detect/browser',
        json={'user_agent': user_agent},
        headers={'X-API-Key': 'your-api-key'}
    )
    return response.json()

# Example usage
browser_info = detect_browser(request.headers.get('User-Agent'))
print(f"Browser: {browser_info['browser']['name']}")
print(f"Version: {browser_info['browser']['version']}")

cURL

curl -X POST "https://api.tinyfn.io/v1/detect/browser" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15"}'

Common Use Cases

  • Bug Workarounds: Apply fixes for known browser bugs
  • Feature Polyfills: Load polyfills for older browsers
  • Analytics: Track browser distribution in your audience
  • Deprecation Notices: Show upgrade notices for old browsers
  • Support Pages: Provide browser-specific instructions

Best Practices

  1. Prefer feature detection: Test for features, not browser names
  2. Be specific: Target specific versions when fixing bugs
  3. Stay updated: Browser detection patterns change frequently
  4. Document workarounds: Note why browser-specific code exists

Try the Browser Detection API

Get your free API key and start detecting browsers in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key