or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

browser-detection.mdchrome-shims.mdcommon-shims.mdfactory-configuration.mdfirefox-shims.mdindex.mdsafari-shims.mdutility-functions.md

browser-detection.mddocs/

0

# Browser Detection

1

2

WebRTC Adapter's browser detection system automatically identifies the WebRTC engine, browser version, and specific capabilities to determine which shims need to be applied.

3

4

## Capabilities

5

6

### Browser Details Object

7

8

The main source of browser information available through `adapter.browserDetails`.

9

10

```javascript { .api }

11

interface IBrowserDetails {

12

/** Browser name: 'chrome', 'firefox', 'safari', or 'Not a browser.' */

13

browser: string;

14

/** Browser version number, null if unable to detect */

15

version: number | null;

16

/** Safari-specific: WebRTC Unified Plan support detection */

17

supportsUnifiedPlan?: boolean;

18

}

19

```

20

21

**Usage Examples:**

22

23

```javascript

24

import adapter from 'webrtc-adapter';

25

26

// Check browser type

27

switch (adapter.browserDetails.browser) {

28

case 'chrome':

29

console.log('Chrome-based browser detected');

30

break;

31

case 'firefox':

32

console.log('Firefox browser detected');

33

break;

34

case 'safari':

35

console.log('Safari browser detected');

36

break;

37

default:

38

console.log('Unsupported or unknown browser');

39

}

40

41

// Check version for feature support

42

if (adapter.browserDetails.browser === 'chrome' && adapter.browserDetails.version >= 74) {

43

console.log('Supports modern WebRTC features');

44

}

45

46

// Safari-specific capability check

47

if (adapter.browserDetails.browser === 'safari' && adapter.browserDetails.supportsUnifiedPlan) {

48

console.log('Safari supports Unified Plan');

49

}

50

```

51

52

### Detect Browser Function

53

54

Low-level browser detection function that analyzes the user agent string.

55

56

```javascript { .api }

57

/**

58

* Detects browser type and version from window object

59

* @param window - Browser window object

60

* @returns Browser details object with detected information

61

*/

62

function detectBrowser(window: Window): IBrowserDetails;

63

```

64

65

**Usage Examples:**

66

67

```javascript

68

import { detectBrowser } from 'webrtc-adapter/src/js/utils.js';

69

70

// Manual browser detection

71

const browserInfo = detectBrowser(window);

72

console.log(`Detected: ${browserInfo.browser} version ${browserInfo.version}`);

73

74

// Custom window object (useful for testing)

75

const mockWindow = { navigator: { userAgent: 'Mozilla/5.0...' } };

76

const mockBrowserInfo = detectBrowser(mockWindow);

77

```

78

79

### Extract Version Function

80

81

Utility function for parsing version numbers from user agent strings using regular expressions.

82

83

```javascript { .api }

84

/**

85

* Extract browser version from user agent string

86

* @param uastring - User agent string to parse

87

* @param expr - Regular expression pattern for version extraction

88

* @param pos - Position in regex match array containing version

89

* @returns Parsed version number or null if not found

90

*/

91

function extractVersion(uastring: string, expr: string, pos: number): number;

92

```

93

94

**Usage Examples:**

95

96

```javascript

97

import adapter from 'webrtc-adapter';

98

99

// Extract Chrome version

100

const chromeVersion = adapter.extractVersion(

101

navigator.userAgent,

102

/Chrom(e|ium)\/(\d+)\./,

103

2

104

);

105

106

// Extract Firefox version

107

const firefoxVersion = adapter.extractVersion(

108

navigator.userAgent,

109

/Firefox\/(\d+)\./,

110

1

111

);

112

113

// Custom version extraction

114

const customVersion = adapter.extractVersion(

115

'MyApp/1.2.3 (Windows)',

116

/MyApp\/(\d+\.\d+\.\d+)/,

117

1

118

);

119

```

120

121

## Browser Detection Logic

122

123

The detection system uses the following priority order:

124

125

1. **Modern Chrome Detection**: Uses `navigator.userAgentData.brands` when available for Chromium detection

126

2. **Firefox Detection**: Checks for `navigator.mozGetUserMedia` presence

127

3. **Chrome/Chromium Detection**: Falls back to `navigator.webkitGetUserMedia` or `window.webkitRTCPeerConnection`

128

4. **Safari Detection**: Identifies Safari through `window.RTCPeerConnection` + WebKit user agent pattern

129

5. **Fallback**: Returns "Not a supported browser" for unrecognized browsers

130

131

## Supported Browsers

132

133

- **Chrome/Chromium**: Includes Chrome, Chromium, Opera, Edge (Chromium-based), and WebView

134

- **Firefox**: All Firefox variants with WebRTC support

135

- **Safari**: Desktop and mobile Safari with WebRTC capabilities

136

- **Unsupported**: Returns appropriate messages for non-WebRTC browsers