0
# System Information
1
2
Extract detailed information about operating systems, browsers, and User-Agent characteristics from device strings.
3
4
## Capabilities
5
6
### User Agent Detection
7
8
Identifies the primary browser or application from the User-Agent string.
9
10
```javascript { .api }
11
/**
12
* Returns the (first) detected user-agent string or null
13
* @returns The primary detected browser/application name or null
14
*/
15
userAgent(): string | null;
16
```
17
18
**Detected User Agents:**
19
- **Browsers**: Chrome, Firefox, Safari, Edge, Opera, IE
20
- **Mobile Browsers**: Opera Mini, Opera Mobi, UCBrowser, MQQBrowser, SamsungBrowser
21
- **Applications**: MicroMessenger (WeChat), baiduboxapp, baidubrowser
22
- **Engines**: Webkit, Gecko, Trident, Presto
23
- **Other**: Coast, Dolfin, Fennec, NetFront, NokiaBrowser, Skyfire, Tizen
24
25
**Usage Examples:**
26
27
```javascript
28
const MobileDetect = require('mobile-detect');
29
30
// Chrome detection
31
const chromeMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
32
console.log(chromeMd.userAgent()); // 'Chrome'
33
34
// Safari on iPhone
35
const safariMd = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Mobile/15E148 Safari/604.1');
36
console.log(safariMd.userAgent()); // 'Safari'
37
38
// Firefox
39
const firefoxMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0');
40
console.log(firefoxMd.userAgent()); // 'Firefox'
41
```
42
43
### Multiple User Agents Detection
44
45
Returns all detected user-agent identifiers from the User-Agent string.
46
47
```javascript { .api }
48
/**
49
* Returns all detected user-agent strings
50
* @returns Array of all detected browser/application names
51
*/
52
userAgents(): string[];
53
```
54
55
**Usage Examples:**
56
57
```javascript
58
// Complex User-Agent with multiple identifiers
59
const complexMd = new MobileDetect('Mozilla/5.0 (Linux; Android 11; SM-G991B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36');
60
61
console.log(complexMd.userAgent()); // 'Chrome' (first detected)
62
console.log(complexMd.userAgents()); // ['Chrome', 'Safari', 'Webkit'] (all detected)
63
64
// Simple case
65
const simpleMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0');
66
console.log(simpleMd.userAgents()); // ['Firefox', 'Gecko']
67
```
68
69
### Operating System Detection
70
71
Identifies the operating system from the User-Agent string.
72
73
```javascript { .api }
74
/**
75
* Returns the detected operating system string or null
76
* @returns The operating system name or null if not detected
77
*/
78
os(): string | null;
79
```
80
81
**Detected Operating Systems:**
82
- **Mobile**: iOS, AndroidOS, BlackBerryOS, webOS, Sailfish
83
- **Desktop**: Windows NT, Mac OS X, Linux
84
- **Other**: Symbian, Windows Phone OS, Windows Phone, Windows CE, BREW, Java
85
86
**Usage Examples:**
87
88
```javascript
89
// iOS detection
90
const iosMd = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X)');
91
console.log(iosMd.os()); // 'iOS'
92
93
// Android detection
94
const androidMd = new MobileDetect('Mozilla/5.0 (Linux; Android 11; SM-G991B)');
95
console.log(androidMd.os()); // 'AndroidOS'
96
97
// Windows detection
98
const windowsMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64)');
99
console.log(windowsMd.os()); // 'Windows NT'
100
101
// macOS detection
102
const macMd = new MobileDetect('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)');
103
console.log(macMd.os()); // 'Mac OS X'
104
```
105
106
## System Categories
107
108
### Mobile Operating Systems
109
- **iOS**: iPhone, iPad, iPod touch operating system
110
- **AndroidOS**: Google Android in all variants
111
- **BlackBerryOS**: BlackBerry devices
112
- **webOS**: Palm/HP webOS, LG webOS
113
- **Sailfish**: Sailfish OS
114
- **Windows Phone**: Microsoft mobile OS variants
115
- **Symbian**: Nokia Symbian OS
116
117
### Desktop Operating Systems
118
- **Windows NT**: All modern Windows versions (7, 8, 10, 11)
119
- **Mac OS X**: macOS in all versions
120
- **Linux**: Various Linux distributions
121
122
### Browser Engines
123
- **Webkit**: Safari, Chrome, many mobile browsers
124
- **Gecko**: Firefox and Mozilla-based browsers
125
- **Trident**: Internet Explorer
126
- **Presto**: Older Opera versions
127
- **Blink**: Chrome, newer Opera (detected as Webkit)
128
129
## Implementation Notes
130
131
- **Pattern Matching**: Uses regex patterns to identify system components
132
- **Caching**: Results are cached per instance for performance
133
- **Priority**: Returns first match for userAgent(), all matches for userAgents()
134
- **Case Insensitive**: Detection is case-insensitive
135
- **Version Support**: Use version() and versionStr() methods for version information
136
- **Fallback**: Returns null when no pattern matches
137
138
## Common Use Cases
139
140
```javascript
141
const md = new MobileDetect(navigator.userAgent);
142
143
// Feature detection based on OS
144
if (md.os() === 'iOS') {
145
// iOS-specific functionality
146
} else if (md.os() === 'AndroidOS') {
147
// Android-specific functionality
148
}
149
150
// Browser-specific optimizations
151
if (md.userAgent() === 'Safari') {
152
// Safari-specific code
153
} else if (md.userAgent() === 'Chrome') {
154
// Chrome-specific code
155
}
156
157
// Multiple browser support check
158
const agents = md.userAgents();
159
if (agents.includes('Webkit')) {
160
// Webkit-based browser functionality
161
}
162
```