browser 3.0.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +1 -1
- data/.prettierignore +1 -0
- data/.rubocop.yml +9 -0
- data/.travis.yml +3 -3
- data/CHANGELOG.md +81 -18
- data/FUNDING.yml +3 -0
- data/README.md +113 -88
- data/bots.yml +300 -294
- data/browser.gemspec +3 -1
- data/lib/browser/base.rb +63 -7
- data/lib/browser/browser.rb +27 -26
- data/lib/browser/chrome.rb +12 -2
- data/lib/browser/device.rb +2 -2
- data/lib/browser/device/unknown.rb +1 -1
- data/lib/browser/duck_duck_go.rb +22 -0
- data/lib/browser/edge.rb +2 -2
- 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/meta.rb +0 -1
- data/lib/browser/meta/base.rb +0 -1
- data/lib/browser/miui_browser.rb +21 -0
- data/lib/browser/platform.rb +5 -5
- data/lib/browser/platform/base.rb +3 -2
- data/lib/browser/platform/ios.rb +1 -1
- data/lib/browser/platform/mac.rb +4 -2
- data/lib/browser/platform/{other.rb → unknown.rb} +3 -3
- data/lib/browser/platform/windows.rb +1 -1
- data/lib/browser/safari.rb +16 -1
- data/lib/browser/samsung_browser.rb +21 -0
- 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/test/browser_test.rb +23 -6
- data/test/test_helper.rb +8 -0
- data/test/ua.yml +17 -1
- data/test/ua_bots.yml +8 -2
- 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 +2 -2
- data/test/unit/duck_duck_go_test.rb +37 -0
- data/test/unit/edge_test.rb +34 -2
- 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/micro_messenger_test.rb +21 -6
- data/test/unit/miui_browser_test.rb +25 -0
- data/test/unit/opera_test.rb +1 -0
- data/test/unit/platform_test.rb +12 -7
- data/test/unit/qq_test.rb +12 -0
- data/test/unit/safari_test.rb +12 -7
- data/test/unit/samsung_browser_test.rb +23 -0
- data/test/unit/sougou_browser_test.rb +41 -0
- metadata +33 -10
- data/lib/browser/meta/modern.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78fd9a10d5ca6461be5395616edcc1456967a595363f027548bf8a9fa0bfdf10
|
4
|
+
data.tar.gz: 599be9a3080333b44234ecf4c7ec21572e81e5dc3d04fccfa66a631bc6897494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca6e173a47d2d1489816eb4794c57abc4fc3ff6f1ae63826570c71213e1177813895595240c995704ff50d22666ddae78900ac8eeea77cff93f3f63397bf4d7a
|
7
|
+
data.tar.gz: a09fe431f93c0dc9dd24ae2b1679538c4f61586b8334458adb41e6475c50da5850a747e1630b3904be57ccc360bc12333632cf1986978417e690aca4f8747356
|
data/.github/ISSUE_TEMPLATE.md
CHANGED
data/.prettierignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.yml
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,55 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
4
|
-
|
5
|
-
-
|
3
|
+
## 5.0.0
|
4
|
+
|
5
|
+
- Rename `Browser::Platform#other?` to `Browser::Platform#unknown?`.
|
6
|
+
- Unknown platforms now return `:unknown_platform` as the id.
|
7
|
+
- Unknown devices now return `:unknown_device` as the id.
|
8
|
+
- Unknown browsers now return `:unknown_browser` as the id.
|
9
|
+
- All the changes above affect how `browser.meta` is composed.
|
10
|
+
- Add method `Browser::Base#unknown?`.
|
11
|
+
- Fix issue with `Browser::Base#safari?` matching full version.
|
12
|
+
- Add Maxthon detection.
|
13
|
+
- Add Google Search App detection.
|
14
|
+
- Add Huawei Browser detection.
|
15
|
+
- Fix Duck Duck Go browser that was being recognized as a bot.
|
16
|
+
- Add Miui Browser detection.
|
17
|
+
- Add `Browser::Base#qq?`.
|
18
|
+
- Fix QQ detection.
|
19
|
+
- Fix Alipay detection.
|
20
|
+
- Add Sougou Browser detection.
|
21
|
+
- User agent has a size limit of 512 bytes. This can be customized through
|
22
|
+
`Browser.user_agent_size_limit`.
|
23
|
+
- Accept-Language has a size limit of 256 bytes. This can be customized through
|
24
|
+
`Browser.accept_language_size_limit`.
|
25
|
+
|
26
|
+
## 4.2.0
|
27
|
+
|
28
|
+
- Fix Chrome Lighthouse detection.
|
29
|
+
- Add Skype to bot list.
|
30
|
+
|
31
|
+
## 4.1.0
|
32
|
+
|
33
|
+
- Add Samsung browser.
|
34
|
+
- Add Google Image Proxy to the bot list.
|
35
|
+
- Add The Knowledge AI bot to the bot list.
|
36
|
+
- Add Go HttpClient to the bot list.
|
37
|
+
- Fix Microsoft Edge detection on Android and iOS.
|
38
|
+
- Fix MicroMessenger detection on Android
|
39
|
+
|
40
|
+
## 4.0.0
|
41
|
+
|
42
|
+
- Add Chrome Lighthouse to bot list.
|
43
|
+
- Add SeobilityBot to the bot list.
|
44
|
+
- Detect Mac-based platforms differently, depending on the version; "Mac OS X"
|
45
|
+
will be returned for versions prior to 10.12, and "macOS" for newer versions.
|
46
|
+
- Remove `Browser.modern_rules` and `Browser::Base#modern?`.
|
47
|
+
- Add DuckDuckGo browser.
|
48
|
+
|
49
|
+
# 3.0.3
|
50
|
+
|
51
|
+
- Deprecate `Browser.modern_rules` and `Browser::Base#modern?`. Theses methods
|
52
|
+
will be removed on the next major released, or by June 1st 2020.
|
6
53
|
|
7
54
|
## 3.0.2
|
8
55
|
|
@@ -17,23 +64,32 @@
|
|
17
64
|
- Add ArchiveTeam's ArchiveBot to the bot list.
|
18
65
|
- Fix QQ Browser detection.
|
19
66
|
- Update modern rules.
|
20
|
-
- You can now define new bot matchers by adding a callable object to
|
67
|
+
- You can now define new bot matchers by adding a callable object to
|
68
|
+
`Browser::Bot.matchers`.
|
21
69
|
- Fix `browser.yandex?` and `browser.sputnik?`.
|
22
|
-
- [BREAKING CHANGE] Removed methods to enable the bot's empty user agent
|
23
|
-
|
70
|
+
- [BREAKING CHANGE] Removed methods to enable the bot's empty user agent
|
71
|
+
detection (`Browser::Bot.detect_empty_ua!` and
|
72
|
+
`Browser::Bot.detect_empty_ua?`).
|
73
|
+
- [BREAKING CHANGE] Bot detection is now more aggressive by default. It matches
|
74
|
+
empty user agents, anything that matches
|
75
|
+
`crawl|fetch|search|monitoring|spider|bot`, and anything listed under
|
76
|
+
https://github.com/fnando/browser/blob/master/bots.yml.
|
24
77
|
- Add Jaunt to the bot list.
|
25
78
|
|
26
79
|
## 2.7.1
|
27
80
|
|
28
|
-
- Handle Snapchat user agents that have a space or an empty string instead of a
|
81
|
+
- Handle Snapchat user agents that have a space or an empty string instead of a
|
82
|
+
slash before the version.
|
29
83
|
- Fix iOS 10+ version detection.
|
30
|
-
- Add fallback versions for instagram and snapchat to avoid NoMethodErrors on
|
84
|
+
- Add fallback versions for instagram and snapchat to avoid NoMethodErrors on
|
85
|
+
unexpected user agents.
|
31
86
|
|
32
87
|
## 2.7.0
|
33
88
|
|
34
89
|
- Add more Slack bots.
|
35
90
|
- Handle instagram user agents that have a slash instead of a space.
|
36
|
-
- Add `Browser::Bot.why?(ua)` to help debugging why a user agent is considered
|
91
|
+
- Add `Browser::Bot.why?(ua)` to help debugging why a user agent is considered
|
92
|
+
bot.
|
37
93
|
- Promote Snapchat to a browser (it was detected as a bot previously).
|
38
94
|
- Detect Edge based on Chrome correctly.
|
39
95
|
- Improve Yandex detection.
|
@@ -49,7 +105,8 @@
|
|
49
105
|
|
50
106
|
- Add GarlikCrawler, ImplisenseBot and WikiDo bots.
|
51
107
|
- Add Mastodon URL expander bot.
|
52
|
-
- Add eZ Publish Link Validator, GermCrawler, Pu_iN Crawler, ZoomBot, and
|
108
|
+
- Add eZ Publish Link Validator, GermCrawler, Pu_iN Crawler, ZoomBot, and
|
109
|
+
ZoominfoBot bots.
|
53
110
|
- Add Datanyze bot.
|
54
111
|
- Add support for Instagram in-app browser.
|
55
112
|
- Add Updown.io monitor bot.
|
@@ -71,13 +128,13 @@
|
|
71
128
|
- Add Jooble bot.
|
72
129
|
- Add Fyre bot.
|
73
130
|
- Drop Rails 4 official support.
|
74
|
-
- Fix accept-language sorting (If HTTP-header has value `en,fr`—without
|
131
|
+
- Fix accept-language sorting (If HTTP-header has value `en,fr`—without
|
132
|
+
qualities—the first language should be `en` instead of `fr`).
|
75
133
|
- Ignore malformed strings when comparing versions.
|
76
134
|
- Fix Facebook detection on newer apps.
|
77
135
|
- Change precedence for bot detection when common libs are used.
|
78
136
|
- Add Yandex's search browser to the exception list.
|
79
137
|
|
80
|
-
|
81
138
|
## v2.5.3
|
82
139
|
|
83
140
|
- Add Google Site Verification to the bot list.
|
@@ -118,8 +175,10 @@
|
|
118
175
|
- Add Google Drive API, Proximic Spider, NewRelic pinger and SocialRank bots.
|
119
176
|
- Add Pinboard in-app browser to the bot exception list.
|
120
177
|
- All browser detection methods can now compare versions.
|
121
|
-
- All platform detection methods can now compare versions (except `#linux?` and
|
122
|
-
|
178
|
+
- All platform detection methods can now compare versions (except `#linux?` and
|
179
|
+
`#firefox_os?`).
|
180
|
+
- Add `browser/aliases`, so you can have methods on the base object (e.g.
|
181
|
+
`browser.mobile?`). See README for instructions.
|
123
182
|
- Remove official support for Rails 3 and Ruby 2.1.
|
124
183
|
|
125
184
|
## v2.3.0
|
@@ -150,7 +209,8 @@
|
|
150
209
|
|
151
210
|
## v2.0.3
|
152
211
|
|
153
|
-
- Fix issue with version detection when no actual version is provided (i.e. the
|
212
|
+
- Fix issue with version detection when no actual version is provided (i.e. the
|
213
|
+
user agent doesn't have any version information).
|
154
214
|
|
155
215
|
## v2.0.2
|
156
216
|
|
@@ -163,9 +223,12 @@
|
|
163
223
|
|
164
224
|
## v2.0.0
|
165
225
|
|
166
|
-
- `Browser#platform` now returns instance of `Browser::Platform`, instead of a
|
167
|
-
|
168
|
-
- `Browser#
|
226
|
+
- `Browser#platform` now returns instance of `Browser::Platform`, instead of a
|
227
|
+
`String`. It contains information about the platform (software).
|
228
|
+
- `Browser#device` was added. It returns information about the device
|
229
|
+
(hardware).
|
230
|
+
- `Browser#accept_language` now returns a list of `Browser::AcceptLanguage`
|
231
|
+
objects.
|
169
232
|
- `Browser#bot` now returns a `Browser::Bot` instance.
|
170
233
|
- Safari running as web app mode is not recognized as Safari anymore.
|
171
234
|
- ruby-2.3+ will always activate frozen strings.
|
data/FUNDING.yml
ADDED
data/README.md
CHANGED
@@ -25,6 +25,7 @@ browser = Browser.new("Some User Agent", accept_language: "en-us")
|
|
25
25
|
browser.bot?
|
26
26
|
browser.chrome?
|
27
27
|
browser.core_media?
|
28
|
+
browser.duck_duck_go?
|
28
29
|
browser.edge? # Newest MS browser
|
29
30
|
browser.electron? # Electron Framework
|
30
31
|
browser.firefox?
|
@@ -33,8 +34,8 @@ browser.ie?
|
|
33
34
|
browser.ie?(6) # detect specific IE version
|
34
35
|
browser.ie?([">8", "<10"]) # detect specific IE (IE9).
|
35
36
|
browser.known? # has the browser been successfully detected?
|
37
|
+
browser.unknown? # the browser wasn't detected.
|
36
38
|
browser.meta # an array with several attributes
|
37
|
-
browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
|
38
39
|
browser.name # readable browser name
|
39
40
|
browser.nokia?
|
40
41
|
browser.opera?
|
@@ -43,6 +44,7 @@ browser.phantom_js?
|
|
43
44
|
browser.quicktime?
|
44
45
|
browser.safari?
|
45
46
|
browser.safari_webapp_mode?
|
47
|
+
browser.samsung_browser?
|
46
48
|
browser.to_s # the meta info joined by space
|
47
49
|
browser.uc_browser?
|
48
50
|
browser.version # major version number
|
@@ -50,9 +52,11 @@ browser.webkit?
|
|
50
52
|
browser.webkit_full_version
|
51
53
|
browser.yandex?
|
52
54
|
browser.wechat?
|
55
|
+
browser.qq?
|
53
56
|
browser.weibo?
|
54
57
|
browser.yandex?
|
55
58
|
browser.sputnik?
|
59
|
+
browser.sougou_browser?
|
56
60
|
|
57
61
|
# Get bot info
|
58
62
|
browser.bot.name
|
@@ -65,6 +69,7 @@ Browser::Bot.why?(ua)
|
|
65
69
|
browser.device
|
66
70
|
browser.device.id
|
67
71
|
browser.device.name
|
72
|
+
browser.device.unknown?
|
68
73
|
browser.device.blackberry_playbook?
|
69
74
|
browser.device.console?
|
70
75
|
browser.device.ipad?
|
@@ -110,7 +115,7 @@ browser.platform.ios_app? # detect webview in an iOS app
|
|
110
115
|
browser.platform.ios_webview? # alias for ios_app?
|
111
116
|
browser.platform.linux?
|
112
117
|
browser.platform.mac?
|
113
|
-
browser.platform.
|
118
|
+
browser.platform.unknown?
|
114
119
|
browser.platform.windows10?
|
115
120
|
browser.platform.windows7?
|
116
121
|
browser.platform.windows8?
|
@@ -129,7 +134,9 @@ browser.platform.windows_xp?
|
|
129
134
|
|
130
135
|
### Aliases
|
131
136
|
|
132
|
-
To add aliases like `mobile?` and `tablet?` to the base object (e.g
|
137
|
+
To add aliases like `mobile?` and `tablet?` to the base object (e.g
|
138
|
+
`browser.mobile?`), require the `browser/aliases` file and extend the
|
139
|
+
Browser::Base object like the following:
|
133
140
|
|
134
141
|
```ruby
|
135
142
|
require "browser/aliases"
|
@@ -141,27 +148,35 @@ browser.mobile? #=> false
|
|
141
148
|
|
142
149
|
### What's being detected?
|
143
150
|
|
144
|
-
- For a list of platform detections, check
|
145
|
-
|
146
|
-
- For a list of
|
151
|
+
- For a list of platform detections, check
|
152
|
+
[lib/browser/platform.rb](https://github.com/fnando/browser/blob/master/lib/browser/platform.rb)
|
153
|
+
- For a list of device detections, check
|
154
|
+
[lib/browser/device.rb](https://github.com/fnando/browser/blob/master/lib/browser/device.rb)
|
155
|
+
- For a list of bot detections, check
|
156
|
+
[bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
|
147
157
|
|
148
|
-
###
|
158
|
+
### Detecting modern browsers
|
149
159
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
* Safari 10+
|
154
|
-
* Firefox 52+
|
155
|
-
* IE11+
|
156
|
-
* Microsoft Edge 39+
|
157
|
-
* Opera 50+
|
158
|
-
|
159
|
-
You can define your own rules. A rule must be a proc/lambda or any object that implements the method === and accepts the browser object. To redefine all rules, clear the existing rules before adding your own.
|
160
|
+
To detect whether a browser can be considered as modern or not, create a method
|
161
|
+
that abstracts your versioning constraints. The following example will consider
|
162
|
+
any of the following browsers as a modern:
|
160
163
|
|
161
164
|
```ruby
|
162
|
-
#
|
163
|
-
Browser.
|
164
|
-
|
165
|
+
# Expects an Browser instance,
|
166
|
+
# like in `Browser.new(user_agent, accept_language: language)`.
|
167
|
+
def modern_browser?(browser)
|
168
|
+
[
|
169
|
+
browser.chrome?(">= 65"),
|
170
|
+
browser.safari?(">= 10"),
|
171
|
+
browser.firefox?(">= 52"),
|
172
|
+
browser.ie?(">= 11") && !browser.compatibility_view?,
|
173
|
+
browser.edge?(">= 15"),
|
174
|
+
browser.opera?(">= 50"),
|
175
|
+
browser.facebook?
|
176
|
+
&& browser.safari_webapp_mode?
|
177
|
+
&& browser.webkit_full_version.to_i >= 602
|
178
|
+
].any?
|
179
|
+
end
|
165
180
|
```
|
166
181
|
|
167
182
|
### Rails integration
|
@@ -172,7 +187,8 @@ Just add it to the Gemfile.
|
|
172
187
|
gem "browser"
|
173
188
|
```
|
174
189
|
|
175
|
-
This adds a helper method called `browser`, that inspects your current user
|
190
|
+
This adds a helper method called `browser`, that inspects your current user
|
191
|
+
agent.
|
176
192
|
|
177
193
|
```erb
|
178
194
|
<% if browser.ie?(6) %>
|
@@ -180,7 +196,8 @@ This adds a helper method called `browser`, that inspects your current user agen
|
|
180
196
|
<% end %>
|
181
197
|
```
|
182
198
|
|
183
|
-
If you want to use Browser on your Rails app but don't want to taint your
|
199
|
+
If you want to use Browser on your Rails app but don't want to taint your
|
200
|
+
controller, use the following line on your Gemfile:
|
184
201
|
|
185
202
|
```ruby
|
186
203
|
gem "browser", require: "browser/browser"
|
@@ -188,7 +205,8 @@ gem "browser", require: "browser/browser"
|
|
188
205
|
|
189
206
|
### Accept Language
|
190
207
|
|
191
|
-
Parses the accept-language header from an HTTP request and produces an array of
|
208
|
+
Parses the accept-language header from an HTTP request and produces an array of
|
209
|
+
language objects sorted by quality.
|
192
210
|
|
193
211
|
```ruby
|
194
212
|
browser = Browser.new("Some User Agent", accept_language: "en-us")
|
@@ -214,16 +232,22 @@ language.name
|
|
214
232
|
#=> "English/United States"
|
215
233
|
```
|
216
234
|
|
217
|
-
Result is always sorted in quality order from highest to lowest. As per the HTTP
|
235
|
+
Result is always sorted in quality order from highest to lowest. As per the HTTP
|
236
|
+
spec:
|
218
237
|
|
219
238
|
- omitting the quality value implies 1.0.
|
220
239
|
- quality value equal to zero means that is not accepted by the client.
|
221
240
|
|
222
241
|
### Internet Explorer
|
223
242
|
|
224
|
-
Internet Explorer has a compatibility view mode that allows newer versions
|
243
|
+
Internet Explorer has a compatibility view mode that allows newer versions
|
244
|
+
(IE8+) to run as an older version. Browser will always return the navigator
|
245
|
+
version, ignoring the compatibility view version, when defined. If you need to
|
246
|
+
get the engine's version, you have to use `Browser#msie_version` and
|
247
|
+
`Browser#msie_full_version`.
|
225
248
|
|
226
|
-
So, let's say an user activates compatibility view in a IE11 browser. This is
|
249
|
+
So, let's say an user activates compatibility view in a IE11 browser. This is
|
250
|
+
what you'll get:
|
227
251
|
|
228
252
|
```ruby
|
229
253
|
browser.version
|
@@ -240,16 +264,16 @@ browser.msie_full_version
|
|
240
264
|
|
241
265
|
browser.compatibility_view?
|
242
266
|
#=> true
|
243
|
-
|
244
|
-
browser.modern?
|
245
|
-
#=> false
|
246
267
|
```
|
247
268
|
|
248
|
-
This behavior changed in `v1.0.0`; previously there wasn't a way of getting the
|
269
|
+
This behavior changed in `v1.0.0`; previously there wasn't a way of getting the
|
270
|
+
real browser version.
|
249
271
|
|
250
272
|
### Safari
|
251
273
|
|
252
|
-
iOS webviews and web apps aren't detected as Safari anymore, so be aware of that
|
274
|
+
iOS webviews and web apps aren't detected as Safari anymore, so be aware of that
|
275
|
+
if that's your case. You can use a combination of platform and webkit detection
|
276
|
+
to do whatever you want.
|
253
277
|
|
254
278
|
```ruby
|
255
279
|
# iPad's Safari running as web app mode.
|
@@ -267,19 +291,25 @@ browser.platform.ios?
|
|
267
291
|
|
268
292
|
### Bots
|
269
293
|
|
270
|
-
The bot detection is quite aggressive. Anything that matches at least one of the
|
294
|
+
The bot detection is quite aggressive. Anything that matches at least one of the
|
295
|
+
following requirements will be considered a bot.
|
271
296
|
|
272
297
|
- Empty user agent string
|
273
298
|
- User agent that matches `/crawl|fetch|search|monitoring|spider|bot/`
|
274
|
-
- Any known bot listed under
|
299
|
+
- Any known bot listed under
|
300
|
+
[bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
|
275
301
|
|
276
|
-
To add custom matchers, you can add a callable object to
|
302
|
+
To add custom matchers, you can add a callable object to
|
303
|
+
`Browser::Bot.matchers`. The following example matches everything that has a
|
304
|
+
`externalhit` substring on it. The bot name will always be `General Bot`.
|
277
305
|
|
278
306
|
```ruby
|
279
307
|
Browser::Bot.matchers << ->(ua, _browser) { ua =~ /externalhit/i }
|
280
308
|
```
|
281
309
|
|
282
|
-
To clear all matchers, including the ones that are bundled, use
|
310
|
+
To clear all matchers, including the ones that are bundled, use
|
311
|
+
`Browser::Bot.matchers.clear`. You can re-add built-in matchers by doing the
|
312
|
+
following:
|
283
313
|
|
284
314
|
```ruby
|
285
315
|
Browser::Bot.matchers += Browser::Bot.default_matchers
|
@@ -298,50 +328,41 @@ You can use the `Browser::Middleware` to redirect user agents.
|
|
298
328
|
|
299
329
|
```ruby
|
300
330
|
use Browser::Middleware do
|
301
|
-
redirect_to "/upgrade"
|
302
|
-
end
|
303
|
-
```
|
304
|
-
|
305
|
-
If you're using Rails, you can use the route helper methods. Just add something like the following to a initializer file (`config/initializers/browser.rb`).
|
306
|
-
|
307
|
-
```ruby
|
308
|
-
Rails.configuration.middleware.use Browser::Middleware do
|
309
|
-
redirect_to upgrade_path unless browser.modern?
|
331
|
+
redirect_to "/upgrade" if browser.ie?
|
310
332
|
end
|
311
333
|
```
|
312
334
|
|
313
|
-
|
335
|
+
If you're using Rails, you can use the route helper methods. Just add something
|
336
|
+
like the following to a initializer file (`config/initializers/browser.rb`).
|
314
337
|
|
315
338
|
```ruby
|
316
339
|
Rails.configuration.middleware.use Browser::Middleware do
|
317
|
-
|
318
|
-
redirect_to upgrade_path(browser: "oldie") if browser.ie? && !browser.modern?
|
319
|
-
redirect_to upgrade_path(browser: "oldfx") if browser.firefox? && !browser.modern?
|
340
|
+
redirect_to upgrade_path if browser.ie?
|
320
341
|
end
|
321
342
|
```
|
322
343
|
|
323
|
-
If you need access to the `Rack::Request` object (e.g. to exclude a path), you
|
344
|
+
If you need access to the `Rack::Request` object (e.g. to exclude a path), you
|
345
|
+
can do so with `request`.
|
324
346
|
|
325
347
|
```ruby
|
326
348
|
Rails.configuration.middleware.use Browser::Middleware do
|
327
|
-
redirect_to upgrade_path
|
349
|
+
redirect_to upgrade_path if browser.ie? && request.env["PATH_INFO"] != "/exclude_me"
|
328
350
|
end
|
329
351
|
```
|
330
352
|
|
331
|
-
###
|
332
|
-
|
333
|
-
#### Troubleshooting
|
353
|
+
### Restrictions
|
334
354
|
|
335
|
-
|
355
|
+
- User agent has a size limit of 512 bytes. This can be customized through
|
356
|
+
`Browser.user_agent_size_limit=(size)`.
|
357
|
+
- Accept-Language has a size limit of 256 bytes. This can be customized through
|
358
|
+
`Browser.accept_language_size_limit=(size)`.
|
336
359
|
|
337
|
-
|
360
|
+
If size is not respected, then `Browser::Error` is raised.
|
338
361
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
`.ua` can now be used to retrieve the full User Agent string.
|
362
|
+
```ruby
|
363
|
+
Browser.user_agent_size_limit = 1024
|
364
|
+
Browser.accept_language_size_limit = 150
|
365
|
+
```
|
345
366
|
|
346
367
|
## Development
|
347
368
|
|
@@ -359,25 +380,28 @@ Once you've made your great commits (include tests, please):
|
|
359
380
|
4. Create a pull request
|
360
381
|
5. That's it!
|
361
382
|
|
362
|
-
Please respect the indentation rules and code style.
|
363
|
-
And
|
383
|
+
Please respect the indentation rules and code style. And use 2 spaces, not tabs.
|
384
|
+
And don't touch the version thing.
|
364
385
|
|
365
386
|
## Configuring environment
|
366
387
|
|
367
|
-
To configure your environment, you must have Ruby and bundler installed. Then
|
388
|
+
To configure your environment, you must have Ruby and bundler installed. Then
|
389
|
+
run `bundle install` to install all dependencies.
|
368
390
|
|
369
391
|
To run tests, execute `./bin/rake`.
|
370
392
|
|
371
393
|
### Adding new features
|
372
394
|
|
373
|
-
Before using your time to code a new feature, open a ticket asking if it makes
|
395
|
+
Before using your time to code a new feature, open a ticket asking if it makes
|
396
|
+
sense and if it's on this project's scope.
|
374
397
|
|
375
398
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
376
399
|
|
377
400
|
#### Adding a new bot
|
378
401
|
|
379
402
|
1. Add the user agent to `test/ua_bots.yml`.
|
380
|
-
2. Add the readable name to `bots.yml`. The key must be something that matches
|
403
|
+
2. Add the readable name to `bots.yml`. The key must be something that matches
|
404
|
+
the user agent, in lowercased text.
|
381
405
|
3. Run tests.
|
382
406
|
|
383
407
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
@@ -386,42 +410,43 @@ Don't forget to add a new entry to `CHANGELOG.md`.
|
|
386
410
|
|
387
411
|
1. Add the user agent to `test/ua_search_engines.yml`.
|
388
412
|
2. Add the same user agent to `test/ua_bots.yml`.
|
389
|
-
3. Add the readable name to `search_engines.yml`. The key must be something that
|
413
|
+
3. Add the readable name to `search_engines.yml`. The key must be something that
|
414
|
+
matches the user agent, in lowercased text.
|
390
415
|
4. Run tests.
|
391
416
|
|
392
417
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
393
418
|
|
394
419
|
#### Wrong browser/platform/device detection
|
395
420
|
|
396
|
-
If you know how to fix it, follow the "Writing code" above. Open an issue
|
421
|
+
If you know how to fix it, follow the "Writing code" above. Open an issue
|
422
|
+
otherwise; make sure you fill in the issue template with all the required
|
423
|
+
information.
|
397
424
|
|
398
425
|
## Maintainer
|
399
426
|
|
400
|
-
|
427
|
+
- Nando Vieira - http://nandovieira.com
|
401
428
|
|
402
429
|
## Contributors
|
403
430
|
|
404
|
-
|
431
|
+
- https://github.com/fnando/browser/contributors
|
405
432
|
|
406
433
|
## License
|
407
434
|
|
408
435
|
(The MIT License)
|
409
436
|
|
410
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
IN
|
425
|
-
|
426
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
427
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
437
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
438
|
+
this software and associated documentation files (the 'Software'), to deal in
|
439
|
+
the Software without restriction, including without limitation the rights to
|
440
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
441
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
442
|
+
subject to the following conditions:
|
443
|
+
|
444
|
+
The above copyright notice and this permission notice shall be included in all
|
445
|
+
copies or substantial portions of the Software.
|
446
|
+
|
447
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
448
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
449
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
450
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
451
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
452
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|