device_detector 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/README.md +19 -5
- data/lib/device_detector/browser.rb +141 -7
- data/lib/device_detector/client_hint.rb +100 -32
- data/lib/device_detector/device.rb +188 -1
- data/lib/device_detector/os.rb +109 -7
- data/lib/device_detector/parser.rb +6 -5
- data/lib/device_detector/version.rb +1 -1
- data/lib/device_detector.rb +56 -23
- data/regexes/bots.yml +1242 -213
- data/regexes/client/browser_engine.yml +11 -2
- data/regexes/client/browsers.yml +543 -102
- data/regexes/client/feed_readers.yml +1 -1
- data/regexes/client/hints/apps.yml +29 -3
- data/regexes/client/hints/browsers.yml +87 -5
- data/regexes/client/libraries.yml +107 -1
- data/regexes/client/mediaplayers.yml +15 -1
- data/regexes/client/mobile_apps.yml +413 -117
- data/regexes/client/pim.yml +36 -2
- data/regexes/device/car_browsers.yml +16 -0
- data/regexes/device/consoles.yml +18 -5
- data/regexes/device/mobiles.yml +4180 -1210
- data/regexes/device/notebooks.yml +14 -1
- data/regexes/device/portable_media_player.yml +7 -1
- data/regexes/device/shell_tv.yml +12 -0
- data/regexes/device/televisions.yml +409 -47
- data/regexes/oss.yml +661 -238
- metadata +3 -3
@@ -14,12 +14,12 @@ class DeviceDetector
|
|
14
14
|
return if headers.nil?
|
15
15
|
|
16
16
|
@headers = headers
|
17
|
-
@full_version =
|
17
|
+
@full_version = extract_full_version
|
18
18
|
@browser_list = extract_browser_list
|
19
19
|
@app_name = extract_app_name
|
20
|
-
@platform =
|
20
|
+
@platform = extract_platform
|
21
21
|
@platform_version = extract_platform_version
|
22
|
-
@mobile =
|
22
|
+
@mobile = extract_mobile
|
23
23
|
@model = extract_model
|
24
24
|
end
|
25
25
|
|
@@ -27,19 +27,24 @@ class DeviceDetector
|
|
27
27
|
:platform_version
|
28
28
|
|
29
29
|
def browser_name
|
30
|
-
return 'Iridium' if
|
30
|
+
return 'Iridium' if iridium?
|
31
|
+
return '360 Secure Browser' if secure_browser?
|
31
32
|
|
32
33
|
browser_name_from_list || app_name
|
33
34
|
end
|
34
35
|
|
35
36
|
def os_version
|
36
37
|
return windows_version if platform == 'Windows'
|
38
|
+
return lineage_version if lineage_os_app?
|
39
|
+
return fire_os_version if fire_os_app?
|
37
40
|
|
38
41
|
platform_version
|
39
42
|
end
|
40
43
|
|
41
44
|
def os_name
|
42
45
|
return 'Android' if android_app?
|
46
|
+
return 'Lineage OS' if lineage_os_app?
|
47
|
+
return 'Fire OS' if fire_os_app?
|
43
48
|
return unless ['Windows', 'Chromium OS'].include?(platform)
|
44
49
|
|
45
50
|
platform
|
@@ -59,21 +64,27 @@ class DeviceDetector
|
|
59
64
|
|
60
65
|
private
|
61
66
|
|
62
|
-
def extract_platform_version
|
63
|
-
return if headers['Sec-CH-UA-Platform-Version'].nil?
|
64
|
-
return if headers['Sec-CH-UA-Platform-Version'] == ''
|
65
|
-
|
66
|
-
headers['Sec-CH-UA-Platform-Version']
|
67
|
-
end
|
68
|
-
|
69
67
|
# https://github.com/matomo-org/device-detector/blob/28211c6f411528abf41304e07b886fdf322a49b7/Parser/OperatingSystem.php#L330
|
70
68
|
def android_app?
|
71
69
|
%w[com.hisense.odinbrowser com.seraphic.openinet.pre
|
72
|
-
com.appssppa.idesktoppcbrowser].include?(app_name_from_headers)
|
70
|
+
com.appssppa.idesktoppcbrowser every.browser.inc].include?(app_name_from_headers)
|
71
|
+
end
|
72
|
+
|
73
|
+
# https://github.com/matomo-org/device-detector/blob/67ae11199a5129b42fa8b985d372ea834104fe3a/Parser/OperatingSystem.php#L449-L456
|
74
|
+
def fire_os_app?
|
75
|
+
app_name_from_headers == 'org.mozilla.tv.firefox'
|
76
|
+
end
|
77
|
+
|
78
|
+
# https://github.com/matomo-org/device-detector/blob/67ae11199a5129b42fa8b985d372ea834104fe3a/Parser/OperatingSystem.php#L439-L447
|
79
|
+
def lineage_os_app?
|
80
|
+
app_name_from_headers == 'org.lineageos.jelly'
|
73
81
|
end
|
74
82
|
|
83
|
+
# https://github.com/matomo-org/device-detector/blob/75d88bbefb0182f9207c9f48dc39b1bc8c7cc43f/Parser/Client/Browser.php#L1076-L1079
|
75
84
|
def browser_name_from_list
|
76
|
-
@browser_name_from_list ||= browser_list&.reject
|
85
|
+
@browser_name_from_list ||= browser_list&.reject do |b|
|
86
|
+
['Chromium', 'Microsoft Edge'].include?(b.name)
|
87
|
+
end&.last&.name
|
77
88
|
end
|
78
89
|
|
79
90
|
def available_browsers
|
@@ -94,14 +105,35 @@ class DeviceDetector
|
|
94
105
|
major_version < 11 ? '10' : '11'
|
95
106
|
end
|
96
107
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
108
|
+
def lineage_version
|
109
|
+
DeviceDetector::OS
|
110
|
+
.mapped_os_version(platform_version, DeviceDetector::OS::LINEAGE_OS_VERSION_MAPPING)
|
111
|
+
end
|
112
|
+
|
113
|
+
def fire_os_version
|
114
|
+
DeviceDetector::OS
|
115
|
+
.mapped_os_version(platform_version, DeviceDetector::OS::FIRE_OS_VERSION_MAPPING)
|
116
|
+
end
|
117
|
+
|
118
|
+
# https://github.com/matomo-org/device-detector/blob/67ae11199a5129b42fa8b985d372ea834104fe3a/Parser/Client/Browser.php#L923-L929
|
119
|
+
# If the version reported from the client hints is YYYY or YYYY.MM (e.g., 2022 or 2022.04),
|
120
|
+
# then it is the Iridium browser
|
121
|
+
# https://iridiumbrowser.de/news/
|
122
|
+
def iridium?
|
101
123
|
return if browser_list.nil?
|
102
124
|
|
103
125
|
!browser_list.find do |browser|
|
104
|
-
browser.name == 'Chromium' &&
|
126
|
+
browser.name == 'Chromium' && browser.version =~ /^202[0-4]/
|
127
|
+
end.nil?
|
128
|
+
end
|
129
|
+
|
130
|
+
# https://github.com/matomo-org/device-detector/blob/67ae11199a5129b42fa8b985d372ea834104fe3a/Parser/Client/Browser.php#L931-L937
|
131
|
+
# https://bbs.360.cn/thread-16096544-1-1.html
|
132
|
+
def secure_browser?
|
133
|
+
return if browser_list.nil?
|
134
|
+
|
135
|
+
!browser_list.find do |browser|
|
136
|
+
browser.name == 'Chromium' && browser.version =~ /^15/
|
105
137
|
end.nil?
|
106
138
|
end
|
107
139
|
|
@@ -141,9 +173,15 @@ class DeviceDetector
|
|
141
173
|
end
|
142
174
|
|
143
175
|
def extract_browser_list
|
144
|
-
|
176
|
+
extract_browser_list_from_full_version_list ||
|
177
|
+
extract_browser_list_from_header('Sec-CH-UA') ||
|
178
|
+
extract_browser_list_from_header('Sec-CH-UA-Full-Version-List')
|
179
|
+
end
|
145
180
|
|
146
|
-
|
181
|
+
def extract_browser_list_from_header(header)
|
182
|
+
return if headers[header].nil?
|
183
|
+
|
184
|
+
headers[header].split(', ').map do |component|
|
147
185
|
name_and_version = extract_browser_name_and_version(component)
|
148
186
|
next if name_and_version[:name].nil?
|
149
187
|
|
@@ -158,24 +196,54 @@ class DeviceDetector
|
|
158
196
|
{ name: name, version: browser_version }
|
159
197
|
end
|
160
198
|
|
199
|
+
def extract_browser_list_from_full_version_list
|
200
|
+
return if headers['fullVersionList'].nil? && headers['brands'].nil?
|
201
|
+
|
202
|
+
(headers['brands'] || headers['fullVersionList']).map do |item|
|
203
|
+
name = name_from_known_browsers(item['brand'])
|
204
|
+
next if name.nil?
|
205
|
+
|
206
|
+
HintBrowser.new(name, full_version || item['version'])
|
207
|
+
end.compact
|
208
|
+
end
|
209
|
+
|
161
210
|
# https://github.com/matomo-org/device-detector/blob/be1c9ef486c247dc4886668da5ed0b1c49d90ba8/Parser/Client/Browser.php#L865
|
162
211
|
def name_from_known_browsers(name)
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
i == "#{name} Browser"
|
212
|
+
DeviceDetector::Browser::KNOWN_BROWSER_TO_NAME.fetch(name) do
|
213
|
+
available_browsers.find do |i|
|
214
|
+
i == name ||
|
215
|
+
i.gsub(' ', '') == name.gsub(' ', '') ||
|
216
|
+
i == name.gsub('Browser', '') ||
|
217
|
+
i == name.gsub(' Browser', '') ||
|
218
|
+
i == "#{name} Browser"
|
219
|
+
end
|
172
220
|
end
|
173
221
|
end
|
174
222
|
|
175
|
-
def
|
176
|
-
return if headers[
|
223
|
+
def extract_from_header(header)
|
224
|
+
return if headers[header].nil? || headers[header] == ''
|
177
225
|
|
178
|
-
headers[
|
226
|
+
headers[header]
|
227
|
+
end
|
228
|
+
|
229
|
+
def extract_full_version
|
230
|
+
extract_from_header('Sec-CH-UA-Full-Version') || extract_from_header('uaFullVersion')
|
231
|
+
end
|
232
|
+
|
233
|
+
def extract_platform
|
234
|
+
extract_from_header('Sec-CH-UA-Platform') || extract_from_header('platform')
|
235
|
+
end
|
236
|
+
|
237
|
+
def extract_platform_version
|
238
|
+
extract_from_header('Sec-CH-UA-Platform-Version') || extract_from_header('platformVersion')
|
239
|
+
end
|
240
|
+
|
241
|
+
def extract_mobile
|
242
|
+
extract_from_header('Sec-CH-UA-Mobile') || extract_from_header('mobile')
|
243
|
+
end
|
244
|
+
|
245
|
+
def extract_model
|
246
|
+
extract_from_header('Sec-CH-UA-Model') || extract_from_header('model')
|
179
247
|
end
|
180
248
|
end
|
181
249
|
end
|