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

Commit

Permalink
Added Detection of Chromium Edge on Windows
Browse files Browse the repository at this point in the history
Moved bingbot and googlebot detection to beginning of AppleWebKit section to avoid false-positive for Chromium Edge from 'Edg' in bingbot.
Added case 'Edg' to account for Chromium Edge on Windows.
Added test case for Chromium Edge on Windows.
Updated Changelong.

Signed-off-by: Dan Hammer <daniel.m.hammer@gmail.com>
  • Loading branch information
DanMHammer committed Aug 14, 2020
1 parent 48f5012 commit ea81f1e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

- Fix detection of Firefox on iPad.
- Fix detection of Linux ARM-based Android.
- Add detection of Chromium Edge on Windows.

## 0.5.2

Expand Down
8 changes: 8 additions & 0 deletions all_test.go
Expand Up @@ -210,6 +210,14 @@ var uastrings = []struct {
expected: "Mozilla:5.0 Platform:Windows OS:Windows Phone 10.0 Browser:Edge-12.10240 Engine:EdgeHTML Bot:false Mobile:true",
},

// Microsoft Chromium Edge
{
title: "EdgeDesktop",
ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 Edg/83.0.478.37",
expected: "Mozilla:5.0 Platform:Windows OS:Windows 10 Browser:Edge-83.0.478.37 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
expectedOS: &OSInfo{"Windows 10", "Windows", "10"},
},

// Gecko
{
title: "FirefoxMac",
Expand Down
14 changes: 14 additions & 0 deletions browser.go
Expand Up @@ -59,12 +59,26 @@ func (p *UserAgent) detectBrowser(sections []section) {
}
p.browser.Version = sections[sectionIndex].version
if engine.name == "AppleWebKit" {
for _, comment := range engine.comment {
if len(comment) > 5 &&
(strings.HasPrefix(comment, "Googlebot") || strings.HasPrefix(comment, "bingbot")) {
p.undecided = true
break
}
}
switch sections[slen-1].name {
case "Edge":
p.browser.Name = "Edge"
p.browser.Version = sections[slen-1].version
p.browser.Engine = "EdgeHTML"
p.browser.EngineVersion = ""
case "Edg":
if p.undecided != true {
p.browser.Name = "Edge"
p.browser.Version = sections[slen-1].version
p.browser.Engine = "AppleWebKit"
p.browser.EngineVersion = sections[slen-2].version
}
case "OPR":
p.browser.Name = "Opera"
p.browser.Version = sections[slen-1].version
Expand Down

0 comments on commit ea81f1e

Please sign in to comment.