or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

device-detection.mdindex.mdsystem-information.mdversion-testing.md

device-detection.mddocs/

0

# Device Detection

1

2

Core device identification functionality for determining device types and manufacturers through User-Agent string analysis.

3

4

## Capabilities

5

6

### Mobile Device Detection

7

8

Detects if the User-Agent represents a mobile device and returns the manufacturer/family name.

9

10

```javascript { .api }

11

/**

12

* Returns the detected mobile device type/family string or null

13

* @returns The mobile device manufacturer (e.g., 'Sony', 'Samsung', 'iPhone') or null if not mobile

14

* Possible values: Any phone or tablet key, 'UnknownPhone', 'UnknownTablet', 'UnknownMobile', or null

15

*/

16

mobile(): string | null;

17

```

18

19

**Usage Examples:**

20

21

```javascript

22

const MobileDetect = require('mobile-detect');

23

24

// iPhone detection

25

const iphoneMd = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)');

26

console.log(iphoneMd.mobile()); // 'iPhone'

27

28

// Samsung Android detection

29

const samsungMd = new MobileDetect('Mozilla/5.0 (Linux; Android 11; SM-G991B)');

30

console.log(samsungMd.mobile()); // 'Samsung'

31

32

// Desktop detection

33

const desktopMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64)');

34

console.log(desktopMd.mobile()); // null

35

```

36

37

### Phone Detection

38

39

Specifically detects phone devices (excluding tablets) and returns the manufacturer/family.

40

41

```javascript { .api }

42

/**

43

* Returns the detected phone type/family string or null

44

* @returns The phone manufacturer (e.g., 'iPhone', 'Samsung', 'HTC') or null if not a phone

45

*/

46

phone(): string | null;

47

```

48

49

**Detected Phone Families:**

50

- iPhone, BlackBerry, Pixel, HTC, Nexus, Dell, Motorola

51

- Samsung, LG, Sony, Asus, Xiaomi, NokiaLumia, Micromax

52

- Palm, Vertu, Pantech, Fly, Wiko, iMobile, SimValley

53

- Wolfgang, Alcatel, Nintendo, Amoi, INQ, OnePlus, GenericPhone

54

55

**Usage Examples:**

56

57

```javascript

58

// iPhone detection

59

const md1 = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)');

60

console.log(md1.phone()); // 'iPhone'

61

62

// Samsung phone detection

63

const md2 = new MobileDetect('Mozilla/5.0 (Linux; Android 12; SM-G998B)');

64

console.log(md2.phone()); // 'Samsung'

65

66

// iPad (tablet, not phone)

67

const md3 = new MobileDetect('Mozilla/5.0 (iPad; CPU OS 15_0 like Mac OS X)');

68

console.log(md3.phone()); // null

69

console.log(md3.tablet()); // 'iPad'

70

```

71

72

### Tablet Detection

73

74

Detects tablet devices and returns the manufacturer/family name.

75

76

```javascript { .api }

77

/**

78

* Returns the detected tablet type/family string or null

79

* @returns The tablet manufacturer (e.g., 'iPad', 'Samsung', 'Nexus') or null if not a tablet

80

*/

81

tablet(): string | null;

82

```

83

84

**Detected Tablet Families:**

85

- iPad, NexusTablet, GoogleTablet, SamsungTablet, Kindle

86

- SurfaceTablet, HPTablet, AsusTablet, BlackBerryTablet, HTCtablet

87

- MotorolaTablet, NookTablet, AcerTablet, ToshibaTablet, LGTablet

88

- FujitsuTablet, PrestigioTablet, LenovoTablet, DellTablet, YarvikTablet

89

- And 80+ other tablet manufacturers/models

90

91

**Usage Examples:**

92

93

```javascript

94

// iPad detection

95

const md1 = new MobileDetect('Mozilla/5.0 (iPad; CPU OS 15_0 like Mac OS X)');

96

console.log(md1.tablet()); // 'iPad'

97

98

// Samsung tablet detection

99

const md2 = new MobileDetect('Mozilla/5.0 (Linux; Android 12; SM-T870)');

100

console.log(md2.tablet()); // 'SamsungTablet'

101

102

// Phone (not tablet)

103

const md3 = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)');

104

console.log(md3.tablet()); // null

105

console.log(md3.phone()); // 'iPhone'

106

```

107

108

### Size-Based Phone Detection

109

110

Determines if a device should be considered phone-sized based on screen dimensions (browser environments only).

111

112

```javascript { .api }

113

/**

114

* Checks whether the mobile device can be considered as phone regarding screen width

115

* @param maxPhoneWidth - Optional maximum logical pixels to be considered as phone.

116

* If not provided, uses constructor maxPhoneWidth (default: 600)

117

* @returns true if screen width <= maxPhoneWidth, false otherwise,

118

* undefined if screen size not detectable (server-side environments)

119

*/

120

isPhoneSized(maxPhoneWidth?: number): boolean | undefined;

121

122

/**

123

* Static version of isPhoneSized method for current screen

124

* @param maxPhoneWidth - Maximum logical pixels to be considered as phone (required for static version)

125

* @returns true if current screen width <= maxPhoneWidth, false otherwise,

126

* undefined in server-side environments (no window.screen access)

127

*/

128

static isPhoneSized(maxPhoneWidth?: number): boolean | undefined;

129

```

130

131

**Usage Examples:**

132

133

```javascript

134

// Instance method - uses constructor maxPhoneWidth or 600px default

135

const md = new MobileDetect(navigator.userAgent, 768);

136

console.log(md.isPhoneSized()); // true/false/undefined

137

138

// Instance method - override maxPhoneWidth

139

console.log(md.isPhoneSized(480)); // true/false/undefined

140

141

// Static method - check current screen

142

console.log(MobileDetect.isPhoneSized(600)); // true/false/undefined

143

144

// Server-side usage

145

const serverMd = new MobileDetect(req.headers['user-agent']);

146

console.log(serverMd.isPhoneSized()); // undefined (no screen access)

147

```

148

149

## Device Categories

150

151

The library detects devices across these major categories:

152

153

### Phone Manufacturers (41+ supported)

154

- **Apple**: iPhone, iPod

155

- **Google**: Pixel, Nexus phones

156

- **Samsung**: Galaxy series, all Samsung phone models

157

- **Android OEMs**: HTC, LG, Sony, Motorola, OnePlus, Xiaomi

158

- **Other**: BlackBerry, Nokia Lumia, Palm, Vertu, and 30+ more

159

160

### Tablet Manufacturers (100+ supported)

161

- **Apple**: iPad (all models)

162

- **Google**: Nexus tablets, Pixel tablets

163

- **Samsung**: Galaxy Tab series, all Samsung tablet models

164

- **Amazon**: Kindle Fire series

165

- **Microsoft**: Surface tablets

166

- **Other OEMs**: Asus, Acer, Lenovo, HP, Dell, and 90+ more

167

168

## Implementation Notes

169

170

- **Pattern Matching**: Uses extensive regex patterns for device identification

171

- **Caching**: Detection results are cached per instance for performance

172

- **Fallback Detection**: Uses detectmobilebrowsers.com patterns as fallback

173

- **Screen Size**: isPhoneSized() only works in browser environments with screen access

174

- **Updates Required**: Device patterns need regular updates as new devices are released