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 |
|---|---|---|
| Chrome | Blink | Cross-platform |
| Firefox | Gecko | Cross-platform |
| Safari | WebKit | macOS, iOS |
| Edge | Blink | Cross-platform |
| Opera | Blink | Cross-platform |
| Samsung Internet | Blink | Android |
Using the Browser Detection API
TinyFn provides an endpoint to detect browser information:
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"
}
{
"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
- Prefer feature detection: Test for features, not browser names
- Be specific: Target specific versions when fixing bugs
- Stay updated: Browser detection patterns change frequently
- 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