Skip to content

Commit

Permalink
Add additional WebKit browsers
Browse files Browse the repository at this point in the history
Add support for the following:
- Coc Coc Browser
- Headless Chrome
- iOS WebViews
  • Loading branch information
kylekizirian committed Aug 2, 2021
1 parent bc183fb commit 897eb45
Show file tree
Hide file tree
Showing 3 changed files with 27 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
15 changes: 15 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,16 @@ 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",
},

// Dalvik
{
Expand Down
9 changes: 9 additions & 0 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ 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_cow_browser":
case "coc_coc_browser":
p.browser.Name = "Coc Coc"
p.browser.Version = sections[slen-3].version
default:
switch sections[slen-2].name {
case "Electron":
Expand All @@ -96,6 +103,8 @@ func (p *UserAgent) detectBrowser(sections []section) {
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 "FxiOS":
Expand Down

0 comments on commit 897eb45

Please sign in to comment.