Skip to content

Commit

Permalink
Detect Chrome for iOS correctly
Browse files Browse the repository at this point in the history
Chrome for iOS sends the User-Agent as [described here][1]. This change
fixes the detection of Chrome for iOS by handling it as a special case
under AppleWebKit engine.

This fixes #49.

[1]: https://developer.chrome.com/multidevice/user-agent#chrome_for_ios_user_agent.
  • Loading branch information
cskr committed Jan 15, 2019
1 parent 68da1a7 commit 82f141d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ var uastrings = []struct {
ua: "Mozilla/5.0 (Linux; Android 4.2.1; Galaxy Nexus Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19",
expected: "Mozilla:5.0 Platform:Linux OS:Android 4.2.1 Browser:Chrome-18.0.1025.166 Engine:AppleWebKit-535.19 Bot:false Mobile:true",
},
{
title: "Chrome for iOS",
ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 11_3_1 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) CriOS/67.0.3396.87 Mobile/15E302 Safari/604.1",
expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 11_3_1 like Mac OS X Browser:Chrome-67.0.3396.87 Engine:AppleWebKit-604.1.34 Bot:false Mobile:true",
},
{
title: "WebkitNoPlatform",
ua: "Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13",
Expand Down
2 changes: 2 additions & 0 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (p *UserAgent) detectBrowser(sections []section) {
p.browser.Name = "Chrome"
} else if sections[sectionIndex].name == "Chromium" {
p.browser.Name = "Chromium"
} else if sections[sectionIndex].name == "CriOS" {
p.browser.Name = "Chrome"
} else {
p.browser.Name = "Safari"
}
Expand Down

0 comments on commit 82f141d

Please sign in to comment.