Skip to content

Commit 71d2757

Browse files
authored
Merge pull request #887 from dmkt9/fix/73240-2
fix detecting iOS 26
2 parents 87d6bc6 + 70559b6 commit 71d2757

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

__tests__/Device-test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {getOSAndName} from '../lib/Device';
2+
3+
let mockUA;
4+
jest.mock('ua-parser-js', () => {
5+
const actual = jest.requireActual('ua-parser-js');
6+
return {
7+
...actual,
8+
UAParser: function mockUAParser() {
9+
return new actual.UAParser(mockUA);
10+
},
11+
};
12+
});
13+
14+
const UA_IOS_18_1 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Mobile/15E148 Safari/604.1';
15+
const UA_IOS_18_2 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1';
16+
17+
const UA_IOS_26_1 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1';
18+
const UA_IOS_26_2 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0.1 Mobile/15E148 Safari/604.1';
19+
const UA_IOS_26_3 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0.1 Mobile/15E148 Safari/604.1';
20+
const UA_IOS_26_4 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_10 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1.2 Mobile/15E148 Safari/604.1';
21+
const UA_IOS_26_5 = 'Mozilla/5.0 (iPhone; CPU iPhone OS 19_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6.2 Mobile/15E148 Safari/604.1';
22+
23+
describe('getOSAndName', () => {
24+
it('should return iOS version 18', () => {
25+
mockUA = UA_IOS_18_1;
26+
expect(getOSAndName().osVersion).toEqual('18.6');
27+
28+
mockUA = UA_IOS_18_2;
29+
expect(getOSAndName().osVersion).toEqual('18.5');
30+
});
31+
32+
it('should return iOS version 26', () => {
33+
mockUA = UA_IOS_26_1;
34+
expect(getOSAndName().osVersion).toEqual('26');
35+
36+
mockUA = UA_IOS_26_2;
37+
expect(getOSAndName().osVersion).toEqual('26');
38+
39+
mockUA = UA_IOS_26_3;
40+
expect(getOSAndName().osVersion).toEqual('26');
41+
42+
mockUA = UA_IOS_26_4;
43+
expect(getOSAndName().osVersion).toEqual('26');
44+
45+
mockUA = UA_IOS_26_5;
46+
expect(getOSAndName().osVersion).toEqual('26');
47+
});
48+
});

lib/Device.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ function getOSAndName(): DeviceInfo {
1414
let osVersion = os.version;
1515
// Detection logic inspired by UAParser guide on iOS 26:
1616
// https://docs.uaparser.dev/guides/how-to-detect-ios-26-using-javascript.html
17-
if (browser.name === 'Mobile Safari' && browser.major === '26' && os.name === 'iOS' && os.version === '18.6') {
17+
const [osMajor, osMinor] = (os.version ?? '').split('.');
18+
const osMajorInt = parseInt(osMajor, 10);
19+
const osMinorInt = parseInt(osMinor, 10);
20+
if (browser.name === 'Mobile Safari' && browser.major === '26' && os.name === 'iOS' && (osMajorInt > 18 || (osMajorInt === 18 && osMinorInt >= 6))) {
1821
osVersion = '26';
1922
}
2023

0 commit comments

Comments
 (0)