-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser.go
181 lines (172 loc) · 5.25 KB
/
browser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package useragent
import (
"fmt"
"strconv"
"strings"
)
type Browser struct {
Name string
Major int32
Minor int32
}
// BrowserConstants
var ignoredBrowser = map[string]string{
"mozilla": "Mozilla",
"chrome": "Chrome",
}
var possibleBrowsers = map[string]string{
"crios": "Chrome",
"opera": "Opera",
"opera mini": "Opera Mini",
"opios": "Opera Mini",
"opr": "Opera Webkit",
"kindle": "Kindle",
"lunascape": "LunaScape",
"maxthon": "Maxthon",
"netfron": "NetFront",
"jasmine": "Jasmine",
"blazer": "Blazer",
"avant": "Avant",
"iemobile": "IEMobile",
"slim": "SlimBrowser",
"bidubrowser": "Baidu Browser",
"baidubrowser": "Baidu Browser",
"rekonq": "Rekonq",
"chromium": "Chromium",
"flock": "Flock",
"rockmelt": "RockMelt",
"midori": "Midori",
"epiphany": "Epiphany",
"silk": "Silk",
"skyfire": "Skyfire",
"bolt": "Bolt",
"iron": "Iron",
"vivaldi": "Vivaldi",
"iridium": "Iridium",
"phantomjs": "PhantomJS",
"bowser": "Bowser",
"qupzilla": "QupZilla",
"falkon": "Falkon",
"konqueror": "Konqueror",
"trident": "IE11",
// edge|edgios|edga|edg
"edge": "Microsoft Edge",
"edgios": "Microsoft Edge",
"edga": "Microsoft Edge",
"edg": "Microsoft Edge",
"yabrowser": "Yandex",
"avast": "Avast Secure Browser",
"avg": "AVG Secure Browser",
"puffin": "Puffin",
"focus": "Firefox Focus",
"opt": " Opera Touch",
"browser": "UCBrowser",
"comodo_dragon": "Comodo Dragon",
"windowswechat qbcore": "WeChat Desktop for Windows Built-in Browse",
"micromessenger": "WeChat",
"brave": "Brave browser",
"qqbrowserlite": "QQBrowserLite",
"qq": "QQ, aka ShouQ",
"qqbrowser": "QQBrowser",
"mqqbrowser": "QQBrowser",
"baiduboxapp": "Baidu App",
"2345explorer": "2345 Browser",
"metasr": "SouGouBrowser",
"lbbrowser": "LieBao Browser",
"xiaomi": "MIUI Browser",
"fbav": "Facebook App for iOS & Android",
"headlesschrome": "Chrome Headless",
"oculusbrowser": "Oculus Browser",
"sailfishbrowser": "Sailfish Browser",
"omniweb": "OmniWeb",
"arora": "Arora",
"tizenoka": "Tizenoka",
"dolfin": "Dolphin",
"samsungbrowser": "Samsung Browser",
"netscape": "Netscape",
"qihu": "360",
"coast": "Opera Coast",
"fxios": "Firefox iOS",
"qhbrowser": "360",
"qihoobrowser": "360",
"360browser": "360",
"icedragon": "IceDragon",
"iceweasel": "Iceweasel",
"camino": "Camino",
"chimera": "Chimera",
"fennec": "Fennec",
"maemo": "Maemo",
"minimo": "Minimo",
"conkeror": "Conkeror",
"firefox": "Firefox",
"seamonkey": "SeaMonkey",
"k-meleon": "K-Meleon",
"icecat": "IceCat",
"iceape": "IceApe",
"firebird": "Firebird",
"phoenix": "Phoneix",
"palemoon": "Palemoon",
"basilisk": "Basilisk",
"waterfox": "Waterfox",
"polaris": "Polaris",
"lynx": "Lynx",
"dillo": "Dillo",
"icab": "Icab",
"doris": "Doris",
"amaya": "Amaya",
"w3m": "W3M",
"netsurf": "Netsurf",
"sleipnir": "Sleipnir",
"links": "Links",
"gobrowser": "GoBrowser",
"ice": "ICE Browser",
"mosaic": "Mosaic",
"android": "Android Browser",
}
func (ua *UserAgent) guessBrowser() {
browser := Browser{}
browserToken := ""
for token, _ := range ua.clients {
if val, ok := possibleBrowsers[token]; ok {
browserToken = token
browser.Name = val
}
}
if browserToken == "" {
for token, _ := range ua.clients {
if val, ok := ignoredBrowser[token]; ok {
browserToken = token
browser.Name = val
}
}
}
// check whether there is a version field
if ua.exists("version") {
version := strings.ReplaceAll(ua.clients["version"], "/", ".") // replace / to a dot to parse properly
major, minor := parseBrowserVersion(version)
browser.Major = major
browser.Minor = minor
}
// check if there is a version nearby
if ua.exists(browserToken) {
version := ua.clients[browserToken]
major, minor := parseBrowserVersion(version)
browser.Major = major
browser.Minor = minor
}
ua.Browser = browser
}
func parseBrowserVersion(version string) (int32, int32) {
versionSlice := strings.Split(version, ".")
major, err := strconv.Atoi(versionSlice[0])
if err != nil {
fmt.Println("Error parsing major: ", err)
return int32(0), int32(0)
}
minor, err := strconv.Atoi(string(versionSlice[1][0]))
if err != nil {
fmt.Println("Error parsing minor: ", err)
return int32(0), int32(0)
}
return int32(major), int32(minor)
}