From 82f141dea4a85e17a7fbe5170dd972e6a1f4d588 Mon Sep 17 00:00:00 2001 From: Chandra Sekar S Date: Tue, 15 Jan 2019 10:27:53 +0530 Subject: [PATCH] Detect Chrome for iOS correctly 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. --- all_test.go | 5 +++++ browser.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/all_test.go b/all_test.go index cc36e47..a884694 100644 --- a/all_test.go +++ b/all_test.go @@ -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", diff --git a/browser.go b/browser.go index c6a1d24..0758466 100644 --- a/browser.go +++ b/browser.go @@ -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" }