Skip to content

Commit 4d38b7a

Browse files
committed
fix: properly report iOS Chrome / Firefox
1 parent fd9cd23 commit 4d38b7a

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/BrowserDetector.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ export default class BrowserDetector {
104104
identity: 'OmniWeb',
105105
versionSearch: 'OmniWeb/',
106106
},
107+
{
108+
string: wnd.navigator.userAgent,
109+
subString: 'CriOS',
110+
identity: 'Chrome',
111+
versionSearch: 'CriOS',
112+
},
113+
{
114+
string: wnd.navigator.userAgent,
115+
subString: 'FxiOS',
116+
identity: 'Firefox',
117+
versionSearch: 'FxiOS',
118+
},
107119
{
108120
string: wnd.navigator.vendor,
109121
subString: 'Apple',

test/specs/BrowserDetector.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,43 @@ describe(BrowserDetector, () => {
6363
expect(detector.version).toEqual(74)
6464
})
6565

66+
it('reports Safari on iOS', () => {
67+
const detector = createDetector({
68+
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Mobile/15E148 Safari/604.1',
69+
platform: 'iPhone',
70+
vendor: 'Apple Computer, Inc.'
71+
})
72+
73+
expect(detector.OS).toEqual('iOS')
74+
expect(detector.browser).toEqual('Safari')
75+
expect(detector.version).toEqual(15.6)
76+
})
77+
78+
it('reports Chrome on iOS', () => {
79+
const detector = createDetector({
80+
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/104.0.5112.99 Mobile/15E148 Safari/604.1',
81+
platform: 'iPhone',
82+
vendor: 'Apple Computer, Inc.'
83+
})
84+
85+
expect(detector.OS).toEqual('iOS')
86+
expect(detector.browser).toEqual('Chrome')
87+
expect(detector.version).toEqual(104)
88+
})
89+
90+
it('reports Firefox on iOS', () => {
91+
const detector = createDetector({
92+
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/103.1 Mobile/15E148 Safari/605.1.15',
93+
platform: 'iPhone',
94+
vendor: 'Apple Computer, Inc.'
95+
})
96+
97+
expect(detector.OS).toEqual('iOS')
98+
expect(detector.browser).toEqual('Firefox')
99+
expect(detector.version).toEqual(103)
100+
101+
})
102+
66103
interface DetectorProps {
67104
userAgent?: string,
68105
platform?: string,

0 commit comments

Comments
 (0)