browser 4.2.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -1
- data/FUNDING.yml +3 -0
- data/README.md +97 -47
- data/bots.yml +1 -1
- data/lib/browser/base.rb +61 -6
- data/lib/browser/browser.rb +22 -2
- data/lib/browser/chrome.rb +7 -1
- data/lib/browser/device.rb +9 -2
- data/lib/browser/device/samsung.rb +33 -0
- data/lib/browser/device/unknown.rb +1 -1
- data/lib/browser/google_search_app.rb +21 -0
- data/lib/browser/huawei_browser.rb +21 -0
- data/lib/browser/maxthon.rb +21 -0
- data/lib/browser/miui_browser.rb +21 -0
- data/lib/browser/platform.rb +4 -4
- data/lib/browser/platform/ios.rb +1 -1
- data/lib/browser/platform/mac.rb +1 -1
- data/lib/browser/platform/{other.rb → unknown.rb} +3 -3
- data/lib/browser/platform/windows.rb +1 -1
- data/lib/browser/safari.rb +9 -1
- data/lib/browser/sougou_browser.rb +24 -0
- data/lib/browser/{generic.rb → unknown.rb} +3 -3
- data/lib/browser/version.rb +1 -1
- data/samsung.yml +138 -0
- data/test/browser_test.rb +37 -6
- data/test/ua.yml +16 -4
- data/test/unit/adobe_air_test.rb +1 -1
- data/test/unit/alipay_test.rb +6 -0
- data/test/unit/console_test.rb +2 -2
- data/test/unit/device_test.rb +29 -2
- data/test/unit/duck_duck_go_test.rb +2 -0
- data/test/unit/google_search_app_test.rb +54 -0
- data/test/unit/huawei_browser_test.rb +25 -0
- data/test/unit/maxthon_test.rb +25 -0
- data/test/unit/meta_test.rb +9 -0
- data/test/unit/miui_browser_test.rb +25 -0
- data/test/unit/opera_test.rb +1 -0
- data/test/unit/platform_test.rb +6 -6
- data/test/unit/qq_test.rb +12 -0
- data/test/unit/safari_test.rb +12 -7
- data/test/unit/sougou_browser_test.rb +41 -0
- metadata +26 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5b6ed4dfb725a6d4814c3bd7a0a3897c0fe4fdeb9679d048cbb42123d6117c
|
4
|
+
data.tar.gz: b053a5fcf79d5fbea19849bde05125598563ac1b754dcd661f8c9fb96df2f3d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea11931654143308193198a53edf5009dd301e04610e736c7da191c16c3578dd96df95213c787591f916859f604e01a61ef6baf12744a5ad84499dcaf93bf57
|
7
|
+
data.tar.gz: 7983885eca85b9cf2812f37b291020b2a8ef9ba3a7ee1a44f2a28e643fb786e6565d2a9394f57728c0444d82dc0ca7655eb6568b12578d9e50d8d191d7ca20c9
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,37 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 5.1.0
|
4
|
+
|
5
|
+
- Add Samsung device detection.
|
6
|
+
- Delay parsing `Accept-Language` until `Browser::Base#accept_language` is
|
7
|
+
called for the first time.
|
8
|
+
- Bump up default size limit for `Accept-Language` and `User-Agent` to 2048
|
9
|
+
bytes.
|
10
|
+
|
11
|
+
## 5.0.0
|
12
|
+
|
13
|
+
- Rename `Browser::Platform#other?` to `Browser::Platform#unknown?`.
|
14
|
+
- Unknown platforms now return `:unknown_platform` as the id.
|
15
|
+
- Unknown devices now return `:unknown_device` as the id.
|
16
|
+
- Unknown browsers now return `:unknown_browser` as the id.
|
17
|
+
- All the changes above affect how `browser.meta` is composed.
|
18
|
+
- Add method `Browser::Base#unknown?`.
|
19
|
+
- Fix issue with `Browser::Base#safari?` matching full version.
|
20
|
+
- Add Maxthon detection.
|
21
|
+
- Add Google Search App detection.
|
22
|
+
- Add Huawei Browser detection.
|
23
|
+
- Fix Duck Duck Go browser that was being recognized as a bot.
|
24
|
+
- Add Miui Browser detection.
|
25
|
+
- Add `Browser::Base#qq?`.
|
26
|
+
- Fix QQ detection.
|
27
|
+
- Fix Alipay detection.
|
28
|
+
- Add Sougou Browser detection.
|
29
|
+
- User agent has a size limit of 512 bytes. This can be customized through
|
30
|
+
`Browser.user_agent_size_limit`.
|
31
|
+
- Accept-Language has a size limit of 256 bytes. This can be customized through
|
32
|
+
`Browser.accept_language_size_limit`.
|
33
|
+
|
34
|
+
## 4.2.0
|
4
35
|
|
5
36
|
- Fix Chrome Lighthouse detection.
|
6
37
|
- Add Skype to bot list.
|
data/FUNDING.yml
ADDED
data/README.md
CHANGED
@@ -34,6 +34,7 @@ browser.ie?
|
|
34
34
|
browser.ie?(6) # detect specific IE version
|
35
35
|
browser.ie?([">8", "<10"]) # detect specific IE (IE9).
|
36
36
|
browser.known? # has the browser been successfully detected?
|
37
|
+
browser.unknown? # the browser wasn't detected.
|
37
38
|
browser.meta # an array with several attributes
|
38
39
|
browser.name # readable browser name
|
39
40
|
browser.nokia?
|
@@ -51,9 +52,11 @@ browser.webkit?
|
|
51
52
|
browser.webkit_full_version
|
52
53
|
browser.yandex?
|
53
54
|
browser.wechat?
|
55
|
+
browser.qq?
|
54
56
|
browser.weibo?
|
55
57
|
browser.yandex?
|
56
58
|
browser.sputnik?
|
59
|
+
browser.sougou_browser?
|
57
60
|
|
58
61
|
# Get bot info
|
59
62
|
browser.bot.name
|
@@ -66,6 +69,7 @@ Browser::Bot.why?(ua)
|
|
66
69
|
browser.device
|
67
70
|
browser.device.id
|
68
71
|
browser.device.name
|
72
|
+
browser.device.unknown?
|
69
73
|
browser.device.blackberry_playbook?
|
70
74
|
browser.device.console?
|
71
75
|
browser.device.ipad?
|
@@ -86,6 +90,7 @@ browser.device.tv?
|
|
86
90
|
browser.device.vita?
|
87
91
|
browser.device.wii?
|
88
92
|
browser.device.wiiu?
|
93
|
+
browser.device.samsung?
|
89
94
|
browser.device.switch?
|
90
95
|
browser.device.xbox?
|
91
96
|
browser.device.xbox_360?
|
@@ -111,7 +116,7 @@ browser.platform.ios_app? # detect webview in an iOS app
|
|
111
116
|
browser.platform.ios_webview? # alias for ios_app?
|
112
117
|
browser.platform.linux?
|
113
118
|
browser.platform.mac?
|
114
|
-
browser.platform.
|
119
|
+
browser.platform.unknown?
|
115
120
|
browser.platform.windows10?
|
116
121
|
browser.platform.windows7?
|
117
122
|
browser.platform.windows8?
|
@@ -130,7 +135,9 @@ browser.platform.windows_xp?
|
|
130
135
|
|
131
136
|
### Aliases
|
132
137
|
|
133
|
-
To add aliases like `mobile?` and `tablet?` to the base object (e.g
|
138
|
+
To add aliases like `mobile?` and `tablet?` to the base object (e.g
|
139
|
+
`browser.mobile?`), require the `browser/aliases` file and extend the
|
140
|
+
Browser::Base object like the following:
|
134
141
|
|
135
142
|
```ruby
|
136
143
|
require "browser/aliases"
|
@@ -142,13 +149,18 @@ browser.mobile? #=> false
|
|
142
149
|
|
143
150
|
### What's being detected?
|
144
151
|
|
145
|
-
- For a list of platform detections, check
|
146
|
-
|
147
|
-
- For a list of
|
152
|
+
- For a list of platform detections, check
|
153
|
+
[lib/browser/platform.rb](https://github.com/fnando/browser/blob/master/lib/browser/platform.rb)
|
154
|
+
- For a list of device detections, check
|
155
|
+
[lib/browser/device.rb](https://github.com/fnando/browser/blob/master/lib/browser/device.rb)
|
156
|
+
- For a list of bot detections, check
|
157
|
+
[bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
|
148
158
|
|
149
159
|
### Detecting modern browsers
|
150
160
|
|
151
|
-
To detect whether a browser can be considered as modern or not, create a method
|
161
|
+
To detect whether a browser can be considered as modern or not, create a method
|
162
|
+
that abstracts your versioning constraints. The following example will consider
|
163
|
+
any of the following browsers as a modern:
|
152
164
|
|
153
165
|
```ruby
|
154
166
|
# Expects an Browser instance,
|
@@ -176,7 +188,8 @@ Just add it to the Gemfile.
|
|
176
188
|
gem "browser"
|
177
189
|
```
|
178
190
|
|
179
|
-
This adds a helper method called `browser`, that inspects your current user
|
191
|
+
This adds a helper method called `browser`, that inspects your current user
|
192
|
+
agent.
|
180
193
|
|
181
194
|
```erb
|
182
195
|
<% if browser.ie?(6) %>
|
@@ -184,7 +197,8 @@ This adds a helper method called `browser`, that inspects your current user agen
|
|
184
197
|
<% end %>
|
185
198
|
```
|
186
199
|
|
187
|
-
If you want to use Browser on your Rails app but don't want to taint your
|
200
|
+
If you want to use Browser on your Rails app but don't want to taint your
|
201
|
+
controller, use the following line on your Gemfile:
|
188
202
|
|
189
203
|
```ruby
|
190
204
|
gem "browser", require: "browser/browser"
|
@@ -192,7 +206,8 @@ gem "browser", require: "browser/browser"
|
|
192
206
|
|
193
207
|
### Accept Language
|
194
208
|
|
195
|
-
Parses the accept-language header from an HTTP request and produces an array of
|
209
|
+
Parses the accept-language header from an HTTP request and produces an array of
|
210
|
+
language objects sorted by quality.
|
196
211
|
|
197
212
|
```ruby
|
198
213
|
browser = Browser.new("Some User Agent", accept_language: "en-us")
|
@@ -218,16 +233,22 @@ language.name
|
|
218
233
|
#=> "English/United States"
|
219
234
|
```
|
220
235
|
|
221
|
-
Result is always sorted in quality order from highest to lowest. As per the HTTP
|
236
|
+
Result is always sorted in quality order from highest to lowest. As per the HTTP
|
237
|
+
spec:
|
222
238
|
|
223
239
|
- omitting the quality value implies 1.0.
|
224
240
|
- quality value equal to zero means that is not accepted by the client.
|
225
241
|
|
226
242
|
### Internet Explorer
|
227
243
|
|
228
|
-
Internet Explorer has a compatibility view mode that allows newer versions
|
244
|
+
Internet Explorer has a compatibility view mode that allows newer versions
|
245
|
+
(IE8+) to run as an older version. Browser will always return the navigator
|
246
|
+
version, ignoring the compatibility view version, when defined. If you need to
|
247
|
+
get the engine's version, you have to use `Browser#msie_version` and
|
248
|
+
`Browser#msie_full_version`.
|
229
249
|
|
230
|
-
So, let's say an user activates compatibility view in a IE11 browser. This is
|
250
|
+
So, let's say an user activates compatibility view in a IE11 browser. This is
|
251
|
+
what you'll get:
|
231
252
|
|
232
253
|
```ruby
|
233
254
|
browser.version
|
@@ -246,11 +267,14 @@ browser.compatibility_view?
|
|
246
267
|
#=> true
|
247
268
|
```
|
248
269
|
|
249
|
-
This behavior changed in `v1.0.0`; previously there wasn't a way of getting the
|
270
|
+
This behavior changed in `v1.0.0`; previously there wasn't a way of getting the
|
271
|
+
real browser version.
|
250
272
|
|
251
273
|
### Safari
|
252
274
|
|
253
|
-
iOS webviews and web apps aren't detected as Safari anymore, so be aware of that
|
275
|
+
iOS webviews and web apps aren't detected as Safari anymore, so be aware of that
|
276
|
+
if that's your case. You can use a combination of platform and webkit detection
|
277
|
+
to do whatever you want.
|
254
278
|
|
255
279
|
```ruby
|
256
280
|
# iPad's Safari running as web app mode.
|
@@ -268,19 +292,25 @@ browser.platform.ios?
|
|
268
292
|
|
269
293
|
### Bots
|
270
294
|
|
271
|
-
The bot detection is quite aggressive. Anything that matches at least one of the
|
295
|
+
The bot detection is quite aggressive. Anything that matches at least one of the
|
296
|
+
following requirements will be considered a bot.
|
272
297
|
|
273
298
|
- Empty user agent string
|
274
299
|
- User agent that matches `/crawl|fetch|search|monitoring|spider|bot/`
|
275
|
-
- Any known bot listed under
|
300
|
+
- Any known bot listed under
|
301
|
+
[bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
|
276
302
|
|
277
|
-
To add custom matchers, you can add a callable object to
|
303
|
+
To add custom matchers, you can add a callable object to
|
304
|
+
`Browser::Bot.matchers`. The following example matches everything that has a
|
305
|
+
`externalhit` substring on it. The bot name will always be `General Bot`.
|
278
306
|
|
279
307
|
```ruby
|
280
308
|
Browser::Bot.matchers << ->(ua, _browser) { ua =~ /externalhit/i }
|
281
309
|
```
|
282
310
|
|
283
|
-
To clear all matchers, including the ones that are bundled, use
|
311
|
+
To clear all matchers, including the ones that are bundled, use
|
312
|
+
`Browser::Bot.matchers.clear`. You can re-add built-in matchers by doing the
|
313
|
+
following:
|
284
314
|
|
285
315
|
```ruby
|
286
316
|
Browser::Bot.matchers += Browser::Bot.default_matchers
|
@@ -303,7 +333,8 @@ use Browser::Middleware do
|
|
303
333
|
end
|
304
334
|
```
|
305
335
|
|
306
|
-
If you're using Rails, you can use the route helper methods. Just add something
|
336
|
+
If you're using Rails, you can use the route helper methods. Just add something
|
337
|
+
like the following to a initializer file (`config/initializers/browser.rb`).
|
307
338
|
|
308
339
|
```ruby
|
309
340
|
Rails.configuration.middleware.use Browser::Middleware do
|
@@ -311,7 +342,8 @@ Rails.configuration.middleware.use Browser::Middleware do
|
|
311
342
|
end
|
312
343
|
```
|
313
344
|
|
314
|
-
If you need access to the `Rack::Request` object (e.g. to exclude a path), you
|
345
|
+
If you need access to the `Rack::Request` object (e.g. to exclude a path), you
|
346
|
+
can do so with `request`.
|
315
347
|
|
316
348
|
```ruby
|
317
349
|
Rails.configuration.middleware.use Browser::Middleware do
|
@@ -319,6 +351,20 @@ Rails.configuration.middleware.use Browser::Middleware do
|
|
319
351
|
end
|
320
352
|
```
|
321
353
|
|
354
|
+
### Restrictions
|
355
|
+
|
356
|
+
- User agent has a size limit of 2048 bytes. This can be customized through
|
357
|
+
`Browser.user_agent_size_limit=(size)`.
|
358
|
+
- Accept-Language has a size limit of 2048 bytes. This can be customized through
|
359
|
+
`Browser.accept_language_size_limit=(size)`.
|
360
|
+
|
361
|
+
If size is not respected, then `Browser::Error` is raised.
|
362
|
+
|
363
|
+
```ruby
|
364
|
+
Browser.user_agent_size_limit = 4096
|
365
|
+
Browser.accept_language_size_limit = 4096
|
366
|
+
```
|
367
|
+
|
322
368
|
## Development
|
323
369
|
|
324
370
|
### Versioning
|
@@ -335,25 +381,28 @@ Once you've made your great commits (include tests, please):
|
|
335
381
|
4. Create a pull request
|
336
382
|
5. That's it!
|
337
383
|
|
338
|
-
Please respect the indentation rules and code style.
|
339
|
-
And
|
384
|
+
Please respect the indentation rules and code style. And use 2 spaces, not tabs.
|
385
|
+
And don't touch the version thing.
|
340
386
|
|
341
387
|
## Configuring environment
|
342
388
|
|
343
|
-
To configure your environment, you must have Ruby and bundler installed. Then
|
389
|
+
To configure your environment, you must have Ruby and bundler installed. Then
|
390
|
+
run `bundle install` to install all dependencies.
|
344
391
|
|
345
392
|
To run tests, execute `./bin/rake`.
|
346
393
|
|
347
394
|
### Adding new features
|
348
395
|
|
349
|
-
Before using your time to code a new feature, open a ticket asking if it makes
|
396
|
+
Before using your time to code a new feature, open a ticket asking if it makes
|
397
|
+
sense and if it's on this project's scope.
|
350
398
|
|
351
399
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
352
400
|
|
353
401
|
#### Adding a new bot
|
354
402
|
|
355
403
|
1. Add the user agent to `test/ua_bots.yml`.
|
356
|
-
2. Add the readable name to `bots.yml`. The key must be something that matches
|
404
|
+
2. Add the readable name to `bots.yml`. The key must be something that matches
|
405
|
+
the user agent, in lowercased text.
|
357
406
|
3. Run tests.
|
358
407
|
|
359
408
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
@@ -362,42 +411,43 @@ Don't forget to add a new entry to `CHANGELOG.md`.
|
|
362
411
|
|
363
412
|
1. Add the user agent to `test/ua_search_engines.yml`.
|
364
413
|
2. Add the same user agent to `test/ua_bots.yml`.
|
365
|
-
3. Add the readable name to `search_engines.yml`. The key must be something that
|
414
|
+
3. Add the readable name to `search_engines.yml`. The key must be something that
|
415
|
+
matches the user agent, in lowercased text.
|
366
416
|
4. Run tests.
|
367
417
|
|
368
418
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
369
419
|
|
370
420
|
#### Wrong browser/platform/device detection
|
371
421
|
|
372
|
-
If you know how to fix it, follow the "Writing code" above. Open an issue
|
422
|
+
If you know how to fix it, follow the "Writing code" above. Open an issue
|
423
|
+
otherwise; make sure you fill in the issue template with all the required
|
424
|
+
information.
|
373
425
|
|
374
426
|
## Maintainer
|
375
427
|
|
376
|
-
|
428
|
+
- Nando Vieira - http://nandovieira.com
|
377
429
|
|
378
430
|
## Contributors
|
379
431
|
|
380
|
-
|
432
|
+
- https://github.com/fnando/browser/contributors
|
381
433
|
|
382
434
|
## License
|
383
435
|
|
384
436
|
(The MIT License)
|
385
437
|
|
386
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
IN
|
401
|
-
|
402
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
403
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
438
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
439
|
+
this software and associated documentation files (the 'Software'), to deal in
|
440
|
+
the Software without restriction, including without limitation the rights to
|
441
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
442
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
443
|
+
subject to the following conditions:
|
444
|
+
|
445
|
+
The above copyright notice and this permission notice shall be included in all
|
446
|
+
copies or substantial portions of the Software.
|
447
|
+
|
448
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
449
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
450
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
451
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
452
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
453
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bots.yml
CHANGED
@@ -63,7 +63,7 @@ domain re-animator bot: Domain Re-Animator Bot
|
|
63
63
|
domainsbot: DomainsBot
|
64
64
|
domaintunocrawler: DomainTuno
|
65
65
|
dotbot: Dot Bot
|
66
|
-
|
66
|
+
duckduckbot: Duck Duck Go
|
67
67
|
elb-healthchecker: AWS ELB HealthChecker
|
68
68
|
embedly: Embedly
|
69
69
|
eoaagent: EOAAgent
|
data/lib/browser/base.rb
CHANGED
@@ -6,12 +6,11 @@ module Browser
|
|
6
6
|
|
7
7
|
attr_reader :ua
|
8
8
|
|
9
|
-
# Return an array with all preferred languages that this browser accepts.
|
10
|
-
attr_reader :accept_language
|
11
|
-
|
12
9
|
def initialize(ua, accept_language: nil)
|
10
|
+
validate_size(:user_agent, ua.to_s)
|
11
|
+
|
13
12
|
@ua = ua
|
14
|
-
@
|
13
|
+
@accept_language_raw = accept_language.to_s
|
15
14
|
end
|
16
15
|
|
17
16
|
# Return a meta info about this browser.
|
@@ -19,6 +18,14 @@ module Browser
|
|
19
18
|
Meta.get(self)
|
20
19
|
end
|
21
20
|
|
21
|
+
# Return an array with all preferred languages that this browser accepts.
|
22
|
+
def accept_language
|
23
|
+
@accept_language ||= begin
|
24
|
+
validate_size(:accept_language, @accept_language_raw)
|
25
|
+
AcceptLanguage.parse(@accept_language_raw)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
22
29
|
alias_method :to_a, :meta
|
23
30
|
|
24
31
|
# Return meta representation as string.
|
@@ -122,7 +129,7 @@ module Browser
|
|
122
129
|
|
123
130
|
# Detect if browser is Safari.
|
124
131
|
def safari?(expected_version = nil)
|
125
|
-
Safari.new(ua).match? && detect_version?(
|
132
|
+
Safari.new(ua).match? && detect_version?(full_version, expected_version)
|
126
133
|
end
|
127
134
|
|
128
135
|
def safari_webapp_mode?
|
@@ -197,12 +204,49 @@ module Browser
|
|
197
204
|
ua =~ /SamsungBrowser/ && detect_version?(full_version, expected_version)
|
198
205
|
end
|
199
206
|
|
207
|
+
# Detect if browser is Huawei.
|
208
|
+
def huawei_browser?(expected_version = nil)
|
209
|
+
HuaweiBrowser.new(ua).match? &&
|
210
|
+
detect_version?(full_version, expected_version)
|
211
|
+
end
|
212
|
+
|
213
|
+
# Detect if browser is Xiaomi Miui.
|
214
|
+
def miui_browser?(expected_version = nil)
|
215
|
+
MiuiBrowser.new(ua).match? &&
|
216
|
+
detect_version?(full_version, expected_version)
|
217
|
+
end
|
218
|
+
|
219
|
+
# Detect if browser is Maxthon.
|
220
|
+
def maxthon?(expected_version = nil)
|
221
|
+
Maxthon.new(ua).match? && detect_version?(full_version, expected_version)
|
222
|
+
end
|
223
|
+
|
224
|
+
# Detect if browser is QQ.
|
225
|
+
def qq?(expected_version = nil)
|
226
|
+
QQ.new(ua).match? && detect_version?(full_version, expected_version)
|
227
|
+
end
|
228
|
+
|
229
|
+
# Detect if browser is Sougou.
|
230
|
+
def sougou_browser?(expected_version = nil)
|
231
|
+
SougouBrowser.new(ua).match? &&
|
232
|
+
detect_version?(full_version, expected_version)
|
233
|
+
end
|
234
|
+
|
235
|
+
# Detect if browser is Google Search App
|
236
|
+
def google_search_app?(expected_version = nil)
|
237
|
+
ua =~ /GSA/ && detect_version?(full_version, expected_version)
|
238
|
+
end
|
239
|
+
|
200
240
|
def webkit_full_version
|
201
241
|
ua[%r{AppleWebKit/([\d.]+)}, 1] || "0.0"
|
202
242
|
end
|
203
243
|
|
204
244
|
def known?
|
205
|
-
|
245
|
+
!unknown?
|
246
|
+
end
|
247
|
+
|
248
|
+
def unknown?
|
249
|
+
id == :unknown_browser
|
206
250
|
end
|
207
251
|
|
208
252
|
# Detect if browser is a proxy browser.
|
@@ -214,5 +258,16 @@ module Browser
|
|
214
258
|
def electron?(expected_version = nil)
|
215
259
|
Electron.new(ua).match? && detect_version?(full_version, expected_version)
|
216
260
|
end
|
261
|
+
|
262
|
+
private def validate_size(subject, input)
|
263
|
+
actual_bytesize = input.bytesize
|
264
|
+
size_limit = Browser.public_send("#{subject}_size_limit")
|
265
|
+
|
266
|
+
return if actual_bytesize < size_limit
|
267
|
+
|
268
|
+
raise Error,
|
269
|
+
"#{subject} cannot be larger than #{size_limit} bytes; " \
|
270
|
+
"actual size is #{actual_bytesize} bytes"
|
271
|
+
end
|
217
272
|
end
|
218
273
|
end
|