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

Commit 1a36963

Browse files
committed
Detect Electron
Electron was seen as Safari, even if it is based on Chrome. With this commit, is is now detected as Electron.
1 parent 687f22e commit 1a36963

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

all_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ var uastrings = []struct {
541541
ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4",
542542
expected: "Mozilla:5.0 Platform:iPhone OS:CPU iPhone OS 8_3 like Mac OS X Browser:Firefox-1.0 Engine:AppleWebKit-600.1.4 Bot:false Mobile:true",
543543
},
544+
{
545+
title: "Electron",
546+
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",
547+
expected: "Mozilla:5.0 Platform:Windows OS:Windows 10 Browser:Electron-5.0.0 Engine:AppleWebKit-537.36 Bot:false Mobile:false",
548+
},
544549

545550
// Dalvik
546551
{

browser.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,21 @@ func (p *UserAgent) detectBrowser(sections []section) {
7474
p.browser.Name = "YaBrowser"
7575
p.browser.Version = sections[slen-3].version
7676
default:
77-
switch sections[sectionIndex].name {
78-
case "Chrome", "CriOS":
79-
p.browser.Name = "Chrome"
80-
case "Chromium":
81-
p.browser.Name = "Chromium"
82-
case "FxiOS":
83-
p.browser.Name = "Firefox"
77+
switch sections[slen-2].name {
78+
case "Electron":
79+
p.browser.Name = "Electron"
80+
p.browser.Version = sections[slen-2].version
8481
default:
85-
p.browser.Name = "Safari"
82+
switch sections[sectionIndex].name {
83+
case "Chrome", "CriOS":
84+
p.browser.Name = "Chrome"
85+
case "Chromium":
86+
p.browser.Name = "Chromium"
87+
case "FxiOS":
88+
p.browser.Name = "Firefox"
89+
default:
90+
p.browser.Name = "Safari"
91+
}
8692
}
8793
}
8894
// It's possible the google-bot emulates these now

0 commit comments

Comments
 (0)