Skip to content

Commit 7166ce2

Browse files
authoredMar 23, 2020
fix(server): detection new MS Edge Chromium (#3440)
BREAKING CHANGES - Browser and OS name generation are changed switch to new lib ua-parser-js, which has better detection of MS Edge Chromium
1 parent b8b2ed8 commit 7166ce2

15 files changed

+58
-73
lines changed
 

‎lib/helper.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
const fs = require('graceful-fs')
44
const path = require('path')
55
const _ = require('lodash')
6-
const useragent = require('useragent')
6+
const useragent = require('ua-parser-js')
77
const mm = require('minimatch')
88

99
exports.browserFullNameToShort = (fullName) => {
10-
const agent = useragent.parse(fullName)
11-
const isUnknown = agent.family === 'Other' || agent.os.family === 'Other'
12-
return isUnknown ? fullName : `${agent.toAgent()} (${agent.os})`
10+
const ua = useragent(fullName)
11+
if (!ua.browser.name && !ua.browser.version && !ua.os.name && !ua.os.version) {
12+
return fullName
13+
}
14+
return `${ua.browser.name} ${ua.browser.version || '0.0.0'} (${ua.os.name} ${ua.os.version || '0.0.0'})`
1315
}
1416

1517
exports.isDefined = (value) => {

‎package-lock.json

+5-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@
413413
"socket.io": "2.1.1",
414414
"source-map": "^0.6.1",
415415
"tmp": "0.0.33",
416-
"useragent": "2.3.0"
416+
"ua-parser-js": "0.7.21"
417417
},
418418
"devDependencies": {
419419
"browserify": "^16.2.3",

‎test/e2e/basic.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Feature: Basic Testrunner
1717
Then it passes with:
1818
"""
1919
..
20-
HeadlessChrome
20+
Chrome Headless
2121
"""
2222
@not-jenkins
2323
Scenario: Execute a test in Chrome

‎test/e2e/browser_console.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Feature: Browser Console Configuration
128128
When I start Karma
129129
Then the file at test/e2e/console.log contains:
130130
"""
131-
HeadlessChrome
131+
Chrome Headless
132132
"""
133133

134134
Scenario: Execute logging program and disabling terminal
@@ -150,7 +150,7 @@ Feature: Browser Console Configuration
150150
Then it passes with:
151151
"""
152152
.
153-
HeadlessChrome
153+
Chrome Headless
154154
"""
155155

156156
Scenario: Execute logging program and disabling terminal
@@ -170,7 +170,7 @@ Feature: Browser Console Configuration
170170
Then it passes with:
171171
"""
172172
.
173-
HeadlessChrome
173+
Chrome Headless
174174
"""
175175
Scenario: Execute logging program with singleRun
176176
Given a configuration with:

‎test/e2e/custom-context.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ Feature: Custom Context File
1818
Then it passes with:
1919
"""
2020
.
21-
HeadlessChrome
21+
Chrome Headless
2222
"""

‎test/e2e/files.feature

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Feature: Including files
2020
Then it passes with:
2121
"""
2222
.
23-
HeadlessChrome
23+
Chrome Headless
2424
"""
2525

2626
Scenario: Execute a test excluding an explicitly included file
@@ -41,7 +41,7 @@ Feature: Including files
4141
Then it passes with like:
4242
"""
4343
.
44-
HeadlessChrome
44+
Chrome Headless
4545
"""
4646
And it passes with like:
4747
"""
@@ -66,7 +66,7 @@ Feature: Including files
6666
Then it passes with like:
6767
"""
6868
.
69-
HeadlessChrome
69+
Chrome Headless
7070
"""
7171
And it passes with like:
7272
"""
@@ -91,7 +91,7 @@ Feature: Including files
9191
Then it passes with like:
9292
"""
9393
.
94-
HeadlessChrome
94+
Chrome Headless
9595
"""
9696
And it passes with like:
9797
"""
@@ -116,7 +116,7 @@ Feature: Including files
116116
Then it passes with like:
117117
"""
118118
.
119-
HeadlessChrome
119+
Chrome Headless
120120
"""
121121
And it passes with like:
122122
"""
@@ -141,7 +141,7 @@ Feature: Including files
141141
Then it passes with like:
142142
"""
143143
.
144-
HeadlessChrome
144+
Chrome Headless
145145
"""
146146
And it passes with like:
147147
"""
@@ -167,7 +167,7 @@ Feature: Including files
167167
Then it passes with like:
168168
"""
169169
.
170-
HeadlessChrome
170+
Chrome Headless
171171
"""
172172
And it passes with like:
173173
"""

‎test/e2e/headers.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ Feature: Custom Headers
2222
Then it passes with:
2323
"""
2424
.
25-
HeadlessChrome
25+
Chrome Headless
2626
"""

‎test/e2e/middleware.feature

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Feature: Middleware
2121
Then it passes with:
2222
"""
2323
.
24-
HeadlessChrome
24+
Chrome Headless
2525
"""
2626

2727
Scenario: Frameworks can add middleware
@@ -40,5 +40,5 @@ Feature: Middleware
4040
Then it passes with:
4141
"""
4242
.
43-
HeadlessChrome
43+
Chrome Headless
4444
"""

‎test/e2e/proxy.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Feature: Proxying
2020
Then it passes with:
2121
"""
2222
.
23-
HeadlessChrome
23+
Chrome Headless
2424
"""
2525

2626
Scenario: Added by a framework
@@ -39,7 +39,7 @@ Feature: Proxying
3939
Then it passes with:
4040
"""
4141
.
42-
HeadlessChrome
42+
Chrome Headless
4343
"""
4444

4545
Scenario: URLRoot
@@ -60,5 +60,5 @@ Feature: Proxying
6060
Then it passes with:
6161
"""
6262
.
63-
HeadlessChrome
63+
Chrome Headless
6464
"""

‎test/e2e/reconnecting.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ Feature: Passing Options
2222
Then it passes with:
2323
"""
2424
.....
25-
HeadlessChrome
25+
Chrome Headless
2626
"""

‎test/e2e/runInParent.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Feature: runInParent option
2121
Then it passes with:
2222
"""
2323
..
24-
HeadlessChrome
24+
Chrome Headless
2525
"""
2626
@not-jenkins
2727
Scenario: Execute a test in Chrome

‎test/e2e/upstream-proxy.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ Feature: UpstreamProxy
2020
When I start Karma behind a proxy on port 9875 that prepends '/__proxy__/' to the base path
2121
Then it passes with regexp:
2222
"""
23-
HeadlessChrome.*Executed.*SUCCESS
23+
Chrome Headless.*Executed.*SUCCESS
2424
"""

‎test/unit/browser.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Browser', () => {
2828
it('should set fullName and name', () => {
2929
const fullName = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 ' + '(KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7'
3030
browser = new Browser('id', fullName, collection, emitter, socket)
31-
expect(browser.name).to.equal('Chrome 16.0.912 (Mac OS X 10.6.8)')
31+
expect(browser.name).to.equal('Chrome 16.0.912.63 (Mac OS 10.6.8)')
3232
expect(browser.fullName).to.equal(fullName)
3333
})
3434

@@ -66,7 +66,7 @@ describe('Browser', () => {
6666
it('should return browser name', () => {
6767
const fullName = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 ' + '(KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7'
6868
browser = new Browser('id', fullName, collection, emitter, socket)
69-
expect(browser.toString()).to.equal('Chrome 16.0.912 (Mac OS X 10.6.8)')
69+
expect(browser.toString()).to.equal('Chrome 16.0.912.63 (Mac OS 10.6.8)')
7070
})
7171

7272
it('should return verbatim user agent string for unrecognized browser', () => {

‎test/unit/helper.spec.js

+23-15
Original file line numberDiff line numberDiff line change
@@ -14,100 +14,100 @@ describe('helper', () => {
1414
'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 ' +
1515
'(KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25'
1616
)
17-
.to.be.equal('Mobile Safari 6.0.0 (iOS 6.0.0)')
17+
.to.be.equal('Mobile Safari 6.0 (iOS 6.0)')
1818
})
1919

2020
it('should parse Linux', () => {
2121
expecting(
2222
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.19) Gecko/20081216 ' +
2323
'Ubuntu/8.04 (hardy) Firefox/2.0.0.19'
2424
)
25-
.to.be.equal('Firefox 2.0.0 (Ubuntu 8.04.0)')
25+
.to.be.equal('Firefox 2.0.0.19 (Ubuntu 8.04)')
2626
})
2727

2828
it('should degrade gracefully when OS not recognized', () => {
2929
expecting(
3030
'Mozilla/5.0 (X11; U; FreeBSD; i386; en-US; rv:1.7) Gecko/20081216 ' +
3131
'Firefox/2.0.0.19'
32-
).to.be.equal('Firefox 2.0.0 (FreeBSD 0.0.0)')
32+
).to.be.equal('Firefox 2.0.0.19 (FreeBSD 0.0.0)')
3333
})
3434

3535
it('should parse Chrome', () => {
3636
expecting(
3737
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 ' +
3838
'(KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7'
3939
)
40-
.to.be.equal('Chrome 16.0.912 (Mac OS X 10.6.8)')
40+
.to.be.equal('Chrome 16.0.912.63 (Mac OS 10.6.8)')
4141

4242
expecting(
4343
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.15 ' +
4444
'(KHTML, like Gecko) Chrome/18.0.985.0 Safari/535.15'
4545
)
46-
.to.be.equal('Chrome 18.0.985 (Mac OS X 10.6.8)')
46+
.to.be.equal('Chrome 18.0.985.0 (Mac OS 10.6.8)')
4747
})
4848

4949
it('should parse Firefox', () => {
5050
expecting(
5151
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 ' +
5252
'Firefox/7.0.1'
5353
)
54-
.to.be.equal('Firefox 7.0.1 (Mac OS X 10.6.0)')
54+
.to.be.equal('Firefox 7.0.1 (Mac OS 10.6)')
5555
})
5656

5757
it('should parse Opera', () => {
5858
expecting(
5959
'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.9.168 ' +
6060
'Version/11.52'
6161
)
62-
.to.be.equal('Opera 11.52.0 (Mac OS X 10.6.8)')
62+
.to.be.equal('Opera 11.52 (Mac OS 10.6.8)')
6363
})
6464

6565
it('should parse Safari', () => {
6666
expecting(
6767
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.52.7 ' +
6868
'(KHTML, like Gecko) Version/5.1.2 Safari/534.52.7'
6969
)
70-
.to.be.equal('Safari 5.1.2 (Mac OS X 10.6.8)')
70+
.to.be.equal('Safari 5.1.2 (Mac OS 10.6.8)')
7171
})
7272

7373
it('should parse IE7', () => {
7474
expecting(
7575
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; ' +
7676
'.NET CLR 2.0.50727; .NET4.0C; .NET4.0E)'
7777
)
78-
.to.be.equal('IE 7.0.0 (Windows Vista.0.0)')
78+
.to.be.equal('IE 7.0 (Windows Vista)')
7979
})
8080

8181
it('should parse IE8', () => {
8282
expecting(
8383
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; ' +
8484
'SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3)"'
8585
)
86-
.to.be.equal('IE 8.0.0 (Windows 7.0.0)')
86+
.to.be.equal('IE 8.0 (Windows 7)')
8787
})
8888

8989
it('should parse IE9', () => {
9090
expecting(
9191
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; ' +
9292
'.NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)'
9393
)
94-
.to.be.equal('IE 9.0.0 (Windows 7.0.0)')
94+
.to.be.equal('IE 9.0 (Windows 7)')
9595
})
9696

9797
it('should parse IE10', () => {
9898
expecting(
9999
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; ' +
100100
'.NET4.0E; .NET4.0C)'
101101
)
102-
.to.be.equal('IE 10.0.0 (Windows 8.0.0)')
102+
.to.be.equal('IE 10.0 (Windows 8)')
103103
})
104104

105105
it('should parse PhantomJS', () => {
106106
expecting(
107107
'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) ' +
108108
'PhantomJS/1.6.0 Safari/534.34'
109109
)
110-
.to.be.equal('PhantomJS 1.6.0 (Mac OS X 0.0.0)')
110+
.to.be.equal('PhantomJS 1.6.0 (Mac OS 0.0.0)')
111111
})
112112

113113
// Fix for #318
@@ -116,15 +116,23 @@ describe('helper', () => {
116116
'Mozilla/5.0 (Linux; U; Android 4.2; en-us; sdk Build/JB_MR1) ' +
117117
'AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
118118
)
119-
.to.be.equal('Android 4.2.0 (Android 4.2.0)')
119+
.to.be.equal('Android Browser 4.0 (Android 4.2)')
120120
})
121121

122122
it('should parse Headless Chrome', () => {
123123
expecting(
124124
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ' +
125125
'HeadlessChrome/70.0.3538.77 Safari/537.36'
126126
)
127-
.to.be.equal('HeadlessChrome 70.0.3538 (Linux 0.0.0)')
127+
.to.be.equal('Chrome Headless 70.0.3538.77 (Linux x86_64)')
128+
})
129+
130+
it('should parse MS Edge Chromium', () => {
131+
expecting(
132+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' +
133+
'Chrome/80.0.3987.132 Safari/537.36 Edg/80.0.361.66'
134+
)
135+
.to.be.equal('Edge 80.0.361.66 (Windows 10)')
128136
})
129137
})
130138

0 commit comments

Comments
 (0)
Please sign in to comment.