Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit f659b98

Browse files
committed
Added support for Microsoft Edge
Fixes #19
1 parent 35c7f18 commit f659b98

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

all_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ var uastrings = []struct {
4040
{"IE11b32Win7b64MDDRJS", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; MDDRJS; rv:11.0) like Gecko"},
4141
{"IE11Compatibility", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0)"},
4242

43+
// Microsoft Edge
44+
{"EdgeDesktop", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240"},
45+
{"EdgeMobile", "Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10240"},
46+
4347
// Gecko
4448
{"FirefoxMac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8"},
4549
{"FirefoxMacLoc", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"},
@@ -129,6 +133,10 @@ var expected = []string{
129133
"Mozilla:5.0 Platform:Windows OS:Windows 7 Browser:Internet Explorer-11.0 Engine:Trident Bot:false Mobile:false",
130134
"Mozilla:4.0 Platform:Windows OS:Windows 8.1 Browser:Internet Explorer-7.0 Engine:Trident Bot:false Mobile:false",
131135

136+
// Microsoft Edge
137+
"Mozilla:5.0 Platform:Windows OS:Windows NT 10.0 Browser:Edge-12.10240 Engine:EdgeHTML Bot:false Mobile:false",
138+
"Mozilla:5.0 Platform:Windows OS:Windows Phone 10.0 Browser:Edge-12.10240 Engine:EdgeHTML Bot:false Mobile:true",
139+
132140
// Gecko
133141
"Mozilla:5.0 Platform:Macintosh OS:Intel Mac OS X 10.6 Browser:Firefox-4.0b8 Engine:Gecko-20100101 Bot:false Mobile:false",
134142
"Mozilla:5.0 Platform:Macintosh OS:Intel Mac OS X 10.6 Localization:en-US Browser:Firefox-3.6.13 Engine:Gecko-20101203 Bot:false Mobile:false",

browser.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,21 @@ func (p *UserAgent) detectBrowser(sections []section) {
4848
if slen > 2 {
4949
p.browser.Version = sections[2].version
5050
if engine.name == "AppleWebKit" {
51-
if sections[slen-1].name == "OPR" {
51+
switch sections[slen-1].name {
52+
case "Edge":
53+
p.browser.Name = "Edge"
54+
p.browser.Version = sections[slen-1].version
55+
p.browser.Engine = "EdgeHTML"
56+
p.browser.EngineVersion = ""
57+
case "OPR":
5258
p.browser.Name = "Opera"
5359
p.browser.Version = sections[slen-1].version
54-
} else if sections[2].name == "Chrome" {
55-
p.browser.Name = "Chrome"
56-
} else {
57-
p.browser.Name = "Safari"
60+
default:
61+
if sections[2].name == "Chrome" {
62+
p.browser.Name = "Chrome"
63+
} else {
64+
p.browser.Name = "Safari"
65+
}
5866
}
5967
} else if engine.name == "Gecko" {
6068
name := sections[2].name

0 commit comments

Comments
 (0)