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

Commit

Permalink
Merge pull request #84 from kylekizirian/master
Browse files Browse the repository at this point in the history
Add additional WebKit browsers
  • Loading branch information
mssola authored Aug 5, 2021
2 parents bc183fb + 38935c1 commit e13ed2b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- Fix detection of Linux ARM-based Android. See [3b0e113c8047](https://github.com/mssola/user_agent/commit/3b0e113c804708c01de00c27aae07d2acfee40d8).
- Add detection of Chromium Edge on Windows. See [ea81f1e9d61c](https://github.com/mssola/user_agent/commit/ea81f1e9d61c094df4156690a8f4d5481b0d6c4a).
- Add detection of OkHttp. See [6b33e248e796](https://github.com/mssola/user_agent/commit/6b33e248e7969cf3e76128a34d33be88d4eb0dc8).
- Add detection of Coc Coc Browser.
- Add detection of Headless Chrome.
- Add detection of iOS WebViews.

## 0.5.2

Expand Down
25 changes: 25 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ var uastrings = []struct {
expected: "Mozilla:5.0 Platform:Macintosh OS:Intel Mac OS X 10_6_5 Localization:en-US Browser:Chrome-8.0.552.231 Engine:AppleWebKit-534.10 Bot:false Mobile:false",
expectedOS: &OSInfo{"Intel Mac OS X 10_6_5", "Mac OS X", "10.6.5"},
},
{
title: "Headless Chrome",
ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/92.0.4515.107 Safari/537.36",
expected: "Mozilla:5.0 Platform:X11 OS:Linux x86_64 Browser:Headless Chrome-92.0.4515.107 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
},
{
title: "SafariMac",
ua: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16",
Expand Down Expand Up @@ -594,6 +599,26 @@ var uastrings = []struct {
ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) CozyDrive/3.17.0 Chrome/73.0.3683.119 Electron/5.0.0 Safari/537.36",
expected: "Mozilla:5.0 Platform:Windows OS:Windows 10 Browser:Electron-5.0.0 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
},
{
title: "Coc Coc",
ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/96.0.230 Chrome/90.0.4430.230 Safari/537.36",
expected: "Mozilla:5.0 Platform:Macintosh OS:Intel Mac OS X 10_15_7 Browser:Coc Coc-96.0.230 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
},
{
title: "LinkedInApp",
ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 [LinkedInApp]",
expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 14_6 like Mac OS X Browser:Mobile App Engine:AppleWebKit-605.1.15 Bot:false Mobile:true",
},
{
title: "Google App for iOS",
ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/170.0.386351093 Mobile/15E148 Safari/604.1",
expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 14_1 like Mac OS X Browser:Google App-170.0.386351093 Engine:AppleWebKit-605.1.15 Bot:false Mobile:true",
},
{
title: "DuckDuckGo Browser for iOS",
ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.6 Mobile/15E148 DuckDuckGo/7 Safari/605.1.15",
expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 14_6 like Mac OS X Browser:DuckDuckGo-7 Engine:AppleWebKit-605.1.15 Bot:false Mobile:true",
},

// Dalvik
{
Expand Down
13 changes: 13 additions & 0 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,35 @@ func (p *UserAgent) detectBrowser(sections []section) {
case "OPR":
p.browser.Name = "Opera"
p.browser.Version = sections[slen-1].version
case "Mobile":
p.browser.Name = "Mobile App"
p.browser.Version = ""
default:
switch sections[slen-3].name {
case "YaBrowser":
p.browser.Name = "YaBrowser"
p.browser.Version = sections[slen-3].version
case "coc_coc_browser":
p.browser.Name = "Coc Coc"
p.browser.Version = sections[slen-3].version
default:
switch sections[slen-2].name {
case "Electron":
p.browser.Name = "Electron"
p.browser.Version = sections[slen-2].version
case "DuckDuckGo":
p.browser.Name = "DuckDuckGo"
p.browser.Version = sections[slen-2].version
default:
switch sections[sectionIndex].name {
case "Chrome", "CriOS":
p.browser.Name = "Chrome"
case "HeadlessChrome":
p.browser.Name = "Headless Chrome"
case "Chromium":
p.browser.Name = "Chromium"
case "GSA":
p.browser.Name = "Google App"
case "FxiOS":
p.browser.Name = "Firefox"
default:
Expand Down

0 comments on commit e13ed2b

Please sign in to comment.