Skip to content

Commit a937842

Browse files
committed
Improve Windows detection & recognize Windows CE & RT as separate OS variants
1 parent f9836f1 commit a937842

File tree

8 files changed

+343
-35
lines changed

8 files changed

+343
-35
lines changed

src/enums/ua-parser-enums.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,11 @@ export const OS: Readonly<{
373373
WATCHOS: "watchOS";
374374
WEBOS: "WebOS";
375375
WINDOWS: "Windows";
376+
WINDOWS_CE: "Windows CE";
376377
WINDOWS_IOT: "Windows IoT";
377378
WINDOWS_MOBILE: "Windows Mobile";
378379
WINDOWS_PHONE: "Windows Phone";
380+
WINDOWS_RT: "Windows RT";
379381
XBOX: "Xbox";
380382
XUBUNTU: "Xubuntu";
381383
ZENWALK: "Zenwalk";

src/enums/ua-parser-enums.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ const OS = Object.freeze({
388388
WATCHOS: 'watchOS',
389389
WEBOS: 'WebOS',
390390
WINDOWS: 'Windows',
391+
WINDOWS_CE: 'Windows CE',
391392
WINDOWS_IOT: 'Windows IoT',
392393
WINDOWS_MOBILE: 'Windows Mobile',
393394
WINDOWS_PHONE: 'Windows Phone',
395+
WINDOWS_RT: 'Windows RT',
394396
XBOX: 'Xbox',
395397
XUBUNTU: 'Xubuntu',
396398
ZENWALK: 'Zenwalk'

src/main/ua-parser.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,17 @@
299299
//////////////
300300

301301
var windowsVersionMap = {
302-
'ME' : '4.90',
303-
'NT 3.11' : 'NT3.51',
304-
'NT 4.0' : 'NT4.0',
305-
'2000' : 'NT 5.0',
306-
'XP' : ['NT 5.1', 'NT 5.2'],
307-
'Vista' : 'NT 6.0',
308-
'7' : 'NT 6.1',
309-
'8' : 'NT 6.2',
310-
'8.1' : 'NT 6.3',
311-
'10' : ['NT 6.4', 'NT 10.0'],
312-
'RT' : 'ARM'
302+
'ME' : '4.90',
303+
'NT 3.51': '3.51',
304+
'NT 4.0': '4.0',
305+
'2000' : ['5.0', '5.01'],
306+
'XP' : ['5.1', '5.2'],
307+
'Vista' : '6.0',
308+
'7' : '6.1',
309+
'8' : '6.2',
310+
'8.1' : '6.3',
311+
'10' : ['6.4', '10.0'],
312+
'NT' : ''
313313
},
314314

315315
formFactorsMap = {
@@ -946,14 +946,17 @@
946946
os : [[
947947

948948
// Windows
949-
/microsoft (windows) (7|vista|xp)/i // Windows
949+
/(windows nt) (6\.[23]); arm/i // Windows RT
950+
], [[NAME, /N/, 'R'], [VERSION, strMapper, windowsVersionMap]], [
951+
/(windows (?:phone|mobile|iot))(?: os)?[\/ ]?([\d\.]*( se)?)/i, // Windows IoT/Mobile/Phone
952+
// Windows NT/3.1/95/98/ME/2000/XP/Vista/7/8/8.1/10/11
953+
/(windows)[\/ ](1[01]|2000|3\.1|7|8(\.1)?|9[58]|me|vista|xp)/i
954+
], [NAME, VERSION], [
955+
/windows nt ?([\d\.\)]*)(?!.+xbox)/i,
956+
/\bwin(?=3| ?9|n)(?:nt| 9x )?([\d\.;]*)/i
957+
], [[VERSION, /(;|\))/g, '', strMapper, windowsVersionMap], [NAME, WINDOWS]], [
958+
/(windows ce)\/?([\d\.]*)/i // Windows CE
950959
], [NAME, VERSION], [
951-
/(windows (?:phone(?: os)?|mobile|iot))[\/ ]?([\d\.\w ]*)/i // Windows Phone
952-
], [NAME, [VERSION, strMapper, windowsVersionMap]], [
953-
/windows nt 6\.2; (arm)/i, // Windows RT
954-
/windows[\/ ]([ntce\d\. ]+\w)(?!.+xbox)/i,
955-
/(?:win(?=3|9|n)|win 9x )([nt\d\.]+)/i
956-
], [[VERSION, strMapper, windowsVersionMap], [NAME, WINDOWS]], [
957960

958961
// iOS/macOS
959962
/[adehimnop]{4,7}\b(?:.*os ([\w]+) like mac|; opera)/i, // iOS

test/data/ua/os/windows-ce.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"desc" : "Windows CE",
4+
"ua" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11)",
5+
"expect" :
6+
{
7+
"name" : "Windows CE",
8+
"version" : "undefined"
9+
}
10+
},
11+
{
12+
"desc" : "Windows CE",
13+
"ua" : "Mozilla/4.0 (PDA; Windows CE/1.0.1) NetFront/3.0",
14+
"expect" :
15+
{
16+
"name" : "Windows CE",
17+
"version" : "1.0.1"
18+
}
19+
}
20+
]

test/data/ua/os/windows-mobile.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,23 @@
1616
"name" : "Windows Mobile",
1717
"version" : "undefined"
1818
}
19+
},
20+
{
21+
"desc" : "Windows Mobile",
22+
"ua" : "Opera/9.7 (Windows Mobile; PPC; Opera Mobi/35166; U; en) Presto/2.2.1",
23+
"expect" :
24+
{
25+
"name" : "Windows Mobile",
26+
"version" : "undefined"
27+
}
28+
},
29+
{
30+
"desc" : "Windows Mobile 6.1",
31+
"ua" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11) 320x240; VZW; Motorola-Q9c; Windows Mobile 6.1 Standard",
32+
"expect" :
33+
{
34+
"name" : "Windows Mobile",
35+
"version" : "6.1"
36+
}
1937
}
2038
]

test/data/ua/os/windows-phone.json

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,32 @@
99
}
1010
},
1111
{
12-
"desc" : "Windows Phone OS",
12+
"desc" : "Windows Phone 6.5",
13+
"ua" : "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; HTC_Touch2_T3333; Windows Phone 6.5)",
14+
"expect" :
15+
{
16+
"name" : "Windows Phone",
17+
"version" : "6.5"
18+
}
19+
},
20+
{
21+
"desc" : "Windows Phone 7.0",
1322
"ua" : "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; DELL; Venue Pro)",
1423
"expect" :
1524
{
16-
"name" : "Windows Phone OS",
25+
"name" : "Windows Phone",
1726
"version" : "7.0"
1827
}
1928
},
29+
{
30+
"desc" : "Windows Phone 7.5",
31+
"ua" : "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)",
32+
"expect" :
33+
{
34+
"name" : "Windows Phone",
35+
"version" : "7.5"
36+
}
37+
},
2038
{
2139
"desc" : "Windows Phone 8",
2240
"ua" : "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; HTC; Windows Phone 8X by HTC)",
@@ -25,5 +43,14 @@
2543
"name" : "Windows Phone",
2644
"version" : "8.0"
2745
}
46+
},
47+
{
48+
"desc" : "Windows Phone 8.1",
49+
"ua" : "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 635) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537",
50+
"expect" :
51+
{
52+
"name" : "Windows Phone",
53+
"version" : "8.1"
54+
}
2855
}
2956
]

test/data/ua/os/windows-rt.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"desc" : "Windows RT 8",
4+
"ua" : "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0)",
5+
"expect" :
6+
{
7+
"name" : "Windows RT",
8+
"version" : "8"
9+
}
10+
},
11+
{
12+
"desc" : "Windows RT 8.1",
13+
"ua" : "Mozilla/5.0 (Windows NT 6.3; ARM; Trident/7.0; Touch; rv:11.0) like Gecko",
14+
"expect" :
15+
{
16+
"name" : "Windows RT",
17+
"version" : "8.1"
18+
}
19+
}
20+
]

0 commit comments

Comments
 (0)