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

Commit 82f141d

Browse files
committed
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.
1 parent 68da1a7 commit 82f141d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

all_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ var uastrings = []struct {
466466
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",
467467
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",
468468
},
469+
{
470+
title: "Chrome for iOS",
471+
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",
472+
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",
473+
},
469474
{
470475
title: "WebkitNoPlatform",
471476
ua: "Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13",

browser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ func (p *UserAgent) detectBrowser(sections []section) {
7373
p.browser.Name = "Chrome"
7474
} else if sections[sectionIndex].name == "Chromium" {
7575
p.browser.Name = "Chromium"
76+
} else if sections[sectionIndex].name == "CriOS" {
77+
p.browser.Name = "Chrome"
7678
} else {
7779
p.browser.Name = "Safari"
7880
}

0 commit comments

Comments
 (0)