browser 3.0.3 → 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/.github/ISSUE_TEMPLATE.md +1 -1
- data/.prettierignore +1 -0
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +86 -19
- data/FUNDING.yml +3 -0
- data/README.md +101 -64
- data/bots.yml +300 -294
- data/browser.gemspec +3 -1
- data/lib/browser/base.rb +71 -16
- data/lib/browser/browser.rb +27 -26
- data/lib/browser/chrome.rb +12 -2
- 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/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/samsung.yml +138 -0
- data/test/browser_test.rb +37 -6
- data/test/ua.yml +21 -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 +29 -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 +36 -11
- 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: 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/.github/ISSUE_TEMPLATE.md
CHANGED
data/.prettierignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.yml
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,63 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
4
|
-
|
5
|
-
-
|
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
|
35
|
+
|
36
|
+
- Fix Chrome Lighthouse detection.
|
37
|
+
- Add Skype to bot list.
|
38
|
+
|
39
|
+
## 4.1.0
|
40
|
+
|
41
|
+
- Add Samsung browser.
|
42
|
+
- Add Google Image Proxy to the bot list.
|
43
|
+
- Add The Knowledge AI bot to the bot list.
|
44
|
+
- Add Go HttpClient to the bot list.
|
45
|
+
- Fix Microsoft Edge detection on Android and iOS.
|
46
|
+
- Fix MicroMessenger detection on Android
|
47
|
+
|
48
|
+
## 4.0.0
|
49
|
+
|
50
|
+
- Add Chrome Lighthouse to bot list.
|
51
|
+
- Add SeobilityBot to the bot list.
|
52
|
+
- Detect Mac-based platforms differently, depending on the version; "Mac OS X"
|
53
|
+
will be returned for versions prior to 10.12, and "macOS" for newer versions.
|
54
|
+
- Remove `Browser.modern_rules` and `Browser::Base#modern?`.
|
55
|
+
- Add DuckDuckGo browser.
|
6
56
|
|
7
57
|
# 3.0.3
|
8
58
|
|
9
|
-
- Deprecate `Browser.modern_rules` and `Browser::Base#modern?`. Theses methods
|
59
|
+
- Deprecate `Browser.modern_rules` and `Browser::Base#modern?`. Theses methods
|
60
|
+
will be removed on the next major released, or by June 1st 2020.
|
10
61
|
|
11
62
|
## 3.0.2
|
12
63
|
|
@@ -21,23 +72,32 @@
|
|
21
72
|
- Add ArchiveTeam's ArchiveBot to the bot list.
|
22
73
|
- Fix QQ Browser detection.
|
23
74
|
- Update modern rules.
|
24
|
-
- You can now define new bot matchers by adding a callable object to
|
75
|
+
- You can now define new bot matchers by adding a callable object to
|
76
|
+
`Browser::Bot.matchers`.
|
25
77
|
- Fix `browser.yandex?` and `browser.sputnik?`.
|
26
|
-
- [BREAKING CHANGE] Removed methods to enable the bot's empty user agent
|
27
|
-
|
78
|
+
- [BREAKING CHANGE] Removed methods to enable the bot's empty user agent
|
79
|
+
detection (`Browser::Bot.detect_empty_ua!` and
|
80
|
+
`Browser::Bot.detect_empty_ua?`).
|
81
|
+
- [BREAKING CHANGE] Bot detection is now more aggressive by default. It matches
|
82
|
+
empty user agents, anything that matches
|
83
|
+
`crawl|fetch|search|monitoring|spider|bot`, and anything listed under
|
84
|
+
https://github.com/fnando/browser/blob/master/bots.yml.
|
28
85
|
- Add Jaunt to the bot list.
|
29
86
|
|
30
87
|
## 2.7.1
|
31
88
|
|
32
|
-
- Handle Snapchat user agents that have a space or an empty string instead of a
|
89
|
+
- Handle Snapchat user agents that have a space or an empty string instead of a
|
90
|
+
slash before the version.
|
33
91
|
- Fix iOS 10+ version detection.
|
34
|
-
- Add fallback versions for instagram and snapchat to avoid NoMethodErrors on
|
92
|
+
- Add fallback versions for instagram and snapchat to avoid NoMethodErrors on
|
93
|
+
unexpected user agents.
|
35
94
|
|
36
95
|
## 2.7.0
|
37
96
|
|
38
97
|
- Add more Slack bots.
|
39
98
|
- Handle instagram user agents that have a slash instead of a space.
|
40
|
-
- Add `Browser::Bot.why?(ua)` to help debugging why a user agent is considered
|
99
|
+
- Add `Browser::Bot.why?(ua)` to help debugging why a user agent is considered
|
100
|
+
bot.
|
41
101
|
- Promote Snapchat to a browser (it was detected as a bot previously).
|
42
102
|
- Detect Edge based on Chrome correctly.
|
43
103
|
- Improve Yandex detection.
|
@@ -53,7 +113,8 @@
|
|
53
113
|
|
54
114
|
- Add GarlikCrawler, ImplisenseBot and WikiDo bots.
|
55
115
|
- Add Mastodon URL expander bot.
|
56
|
-
- Add eZ Publish Link Validator, GermCrawler, Pu_iN Crawler, ZoomBot, and
|
116
|
+
- Add eZ Publish Link Validator, GermCrawler, Pu_iN Crawler, ZoomBot, and
|
117
|
+
ZoominfoBot bots.
|
57
118
|
- Add Datanyze bot.
|
58
119
|
- Add support for Instagram in-app browser.
|
59
120
|
- Add Updown.io monitor bot.
|
@@ -75,13 +136,13 @@
|
|
75
136
|
- Add Jooble bot.
|
76
137
|
- Add Fyre bot.
|
77
138
|
- Drop Rails 4 official support.
|
78
|
-
- Fix accept-language sorting (If HTTP-header has value `en,fr`—without
|
139
|
+
- Fix accept-language sorting (If HTTP-header has value `en,fr`—without
|
140
|
+
qualities—the first language should be `en` instead of `fr`).
|
79
141
|
- Ignore malformed strings when comparing versions.
|
80
142
|
- Fix Facebook detection on newer apps.
|
81
143
|
- Change precedence for bot detection when common libs are used.
|
82
144
|
- Add Yandex's search browser to the exception list.
|
83
145
|
|
84
|
-
|
85
146
|
## v2.5.3
|
86
147
|
|
87
148
|
- Add Google Site Verification to the bot list.
|
@@ -122,8 +183,10 @@
|
|
122
183
|
- Add Google Drive API, Proximic Spider, NewRelic pinger and SocialRank bots.
|
123
184
|
- Add Pinboard in-app browser to the bot exception list.
|
124
185
|
- All browser detection methods can now compare versions.
|
125
|
-
- All platform detection methods can now compare versions (except `#linux?` and
|
126
|
-
|
186
|
+
- All platform detection methods can now compare versions (except `#linux?` and
|
187
|
+
`#firefox_os?`).
|
188
|
+
- Add `browser/aliases`, so you can have methods on the base object (e.g.
|
189
|
+
`browser.mobile?`). See README for instructions.
|
127
190
|
- Remove official support for Rails 3 and Ruby 2.1.
|
128
191
|
|
129
192
|
## v2.3.0
|
@@ -154,7 +217,8 @@
|
|
154
217
|
|
155
218
|
## v2.0.3
|
156
219
|
|
157
|
-
- Fix issue with version detection when no actual version is provided (i.e. the
|
220
|
+
- Fix issue with version detection when no actual version is provided (i.e. the
|
221
|
+
user agent doesn't have any version information).
|
158
222
|
|
159
223
|
## v2.0.2
|
160
224
|
|
@@ -167,9 +231,12 @@
|
|
167
231
|
|
168
232
|
## v2.0.0
|
169
233
|
|
170
|
-
- `Browser#platform` now returns instance of `Browser::Platform`, instead of a
|
171
|
-
|
172
|
-
- `Browser#
|
234
|
+
- `Browser#platform` now returns instance of `Browser::Platform`, instead of a
|
235
|
+
`String`. It contains information about the platform (software).
|
236
|
+
- `Browser#device` was added. It returns information about the device
|
237
|
+
(hardware).
|
238
|
+
- `Browser#accept_language` now returns a list of `Browser::AcceptLanguage`
|
239
|
+
objects.
|
173
240
|
- `Browser#bot` now returns a `Browser::Bot` instance.
|
174
241
|
- Safari running as web app mode is not recognized as Safari anymore.
|
175
242
|
- 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,6 +34,7 @@ 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
39
|
browser.name # readable browser name
|
38
40
|
browser.nokia?
|
@@ -42,6 +44,7 @@ browser.phantom_js?
|
|
42
44
|
browser.quicktime?
|
43
45
|
browser.safari?
|
44
46
|
browser.safari_webapp_mode?
|
47
|
+
browser.samsung_browser?
|
45
48
|
browser.to_s # the meta info joined by space
|
46
49
|
browser.uc_browser?
|
47
50
|
browser.version # major version number
|
@@ -49,9 +52,11 @@ browser.webkit?
|
|
49
52
|
browser.webkit_full_version
|
50
53
|
browser.yandex?
|
51
54
|
browser.wechat?
|
55
|
+
browser.qq?
|
52
56
|
browser.weibo?
|
53
57
|
browser.yandex?
|
54
58
|
browser.sputnik?
|
59
|
+
browser.sougou_browser?
|
55
60
|
|
56
61
|
# Get bot info
|
57
62
|
browser.bot.name
|
@@ -64,6 +69,7 @@ Browser::Bot.why?(ua)
|
|
64
69
|
browser.device
|
65
70
|
browser.device.id
|
66
71
|
browser.device.name
|
72
|
+
browser.device.unknown?
|
67
73
|
browser.device.blackberry_playbook?
|
68
74
|
browser.device.console?
|
69
75
|
browser.device.ipad?
|
@@ -84,6 +90,7 @@ browser.device.tv?
|
|
84
90
|
browser.device.vita?
|
85
91
|
browser.device.wii?
|
86
92
|
browser.device.wiiu?
|
93
|
+
browser.device.samsung?
|
87
94
|
browser.device.switch?
|
88
95
|
browser.device.xbox?
|
89
96
|
browser.device.xbox_360?
|
@@ -109,7 +116,7 @@ browser.platform.ios_app? # detect webview in an iOS app
|
|
109
116
|
browser.platform.ios_webview? # alias for ios_app?
|
110
117
|
browser.platform.linux?
|
111
118
|
browser.platform.mac?
|
112
|
-
browser.platform.
|
119
|
+
browser.platform.unknown?
|
113
120
|
browser.platform.windows10?
|
114
121
|
browser.platform.windows7?
|
115
122
|
browser.platform.windows8?
|
@@ -128,7 +135,9 @@ browser.platform.windows_xp?
|
|
128
135
|
|
129
136
|
### Aliases
|
130
137
|
|
131
|
-
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:
|
132
141
|
|
133
142
|
```ruby
|
134
143
|
require "browser/aliases"
|
@@ -140,25 +149,30 @@ browser.mobile? #=> false
|
|
140
149
|
|
141
150
|
### What's being detected?
|
142
151
|
|
143
|
-
- For a list of platform detections, check
|
144
|
-
|
145
|
-
- 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)
|
146
158
|
|
147
159
|
### Detecting modern browsers
|
148
160
|
|
149
|
-
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:
|
150
164
|
|
151
165
|
```ruby
|
152
166
|
# Expects an Browser instance,
|
153
167
|
# like in `Browser.new(user_agent, accept_language: language)`.
|
154
168
|
def modern_browser?(browser)
|
155
169
|
[
|
156
|
-
browser.chrome?
|
157
|
-
browser.safari?
|
158
|
-
browser.firefox?
|
159
|
-
browser.ie?
|
160
|
-
browser.edge?
|
161
|
-
browser.opera?
|
170
|
+
browser.chrome?(">= 65"),
|
171
|
+
browser.safari?(">= 10"),
|
172
|
+
browser.firefox?(">= 52"),
|
173
|
+
browser.ie?(">= 11") && !browser.compatibility_view?,
|
174
|
+
browser.edge?(">= 15"),
|
175
|
+
browser.opera?(">= 50"),
|
162
176
|
browser.facebook?
|
163
177
|
&& browser.safari_webapp_mode?
|
164
178
|
&& browser.webkit_full_version.to_i >= 602
|
@@ -174,7 +188,8 @@ Just add it to the Gemfile.
|
|
174
188
|
gem "browser"
|
175
189
|
```
|
176
190
|
|
177
|
-
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.
|
178
193
|
|
179
194
|
```erb
|
180
195
|
<% if browser.ie?(6) %>
|
@@ -182,7 +197,8 @@ This adds a helper method called `browser`, that inspects your current user agen
|
|
182
197
|
<% end %>
|
183
198
|
```
|
184
199
|
|
185
|
-
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:
|
186
202
|
|
187
203
|
```ruby
|
188
204
|
gem "browser", require: "browser/browser"
|
@@ -190,7 +206,8 @@ gem "browser", require: "browser/browser"
|
|
190
206
|
|
191
207
|
### Accept Language
|
192
208
|
|
193
|
-
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.
|
194
211
|
|
195
212
|
```ruby
|
196
213
|
browser = Browser.new("Some User Agent", accept_language: "en-us")
|
@@ -216,16 +233,22 @@ language.name
|
|
216
233
|
#=> "English/United States"
|
217
234
|
```
|
218
235
|
|
219
|
-
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:
|
220
238
|
|
221
239
|
- omitting the quality value implies 1.0.
|
222
240
|
- quality value equal to zero means that is not accepted by the client.
|
223
241
|
|
224
242
|
### Internet Explorer
|
225
243
|
|
226
|
-
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`.
|
227
249
|
|
228
|
-
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:
|
229
252
|
|
230
253
|
```ruby
|
231
254
|
browser.version
|
@@ -244,11 +267,14 @@ browser.compatibility_view?
|
|
244
267
|
#=> true
|
245
268
|
```
|
246
269
|
|
247
|
-
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.
|
248
272
|
|
249
273
|
### Safari
|
250
274
|
|
251
|
-
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.
|
252
278
|
|
253
279
|
```ruby
|
254
280
|
# iPad's Safari running as web app mode.
|
@@ -266,19 +292,25 @@ browser.platform.ios?
|
|
266
292
|
|
267
293
|
### Bots
|
268
294
|
|
269
|
-
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.
|
270
297
|
|
271
298
|
- Empty user agent string
|
272
299
|
- User agent that matches `/crawl|fetch|search|monitoring|spider|bot/`
|
273
|
-
- Any known bot listed under
|
300
|
+
- Any known bot listed under
|
301
|
+
[bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
|
274
302
|
|
275
|
-
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`.
|
276
306
|
|
277
307
|
```ruby
|
278
308
|
Browser::Bot.matchers << ->(ua, _browser) { ua =~ /externalhit/i }
|
279
309
|
```
|
280
310
|
|
281
|
-
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:
|
282
314
|
|
283
315
|
```ruby
|
284
316
|
Browser::Bot.matchers += Browser::Bot.default_matchers
|
@@ -301,7 +333,8 @@ use Browser::Middleware do
|
|
301
333
|
end
|
302
334
|
```
|
303
335
|
|
304
|
-
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`).
|
305
338
|
|
306
339
|
```ruby
|
307
340
|
Rails.configuration.middleware.use Browser::Middleware do
|
@@ -309,7 +342,8 @@ Rails.configuration.middleware.use Browser::Middleware do
|
|
309
342
|
end
|
310
343
|
```
|
311
344
|
|
312
|
-
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`.
|
313
347
|
|
314
348
|
```ruby
|
315
349
|
Rails.configuration.middleware.use Browser::Middleware do
|
@@ -317,20 +351,19 @@ Rails.configuration.middleware.use Browser::Middleware do
|
|
317
351
|
end
|
318
352
|
```
|
319
353
|
|
320
|
-
###
|
354
|
+
### Restrictions
|
321
355
|
|
322
|
-
|
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)`.
|
323
360
|
|
324
|
-
|
361
|
+
If size is not respected, then `Browser::Error` is raised.
|
325
362
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
##### `NoMethodError: undefined method 'user_agent'`
|
332
|
-
|
333
|
-
`.ua` can now be used to retrieve the full User Agent string.
|
363
|
+
```ruby
|
364
|
+
Browser.user_agent_size_limit = 4096
|
365
|
+
Browser.accept_language_size_limit = 4096
|
366
|
+
```
|
334
367
|
|
335
368
|
## Development
|
336
369
|
|
@@ -348,25 +381,28 @@ Once you've made your great commits (include tests, please):
|
|
348
381
|
4. Create a pull request
|
349
382
|
5. That's it!
|
350
383
|
|
351
|
-
Please respect the indentation rules and code style.
|
352
|
-
And
|
384
|
+
Please respect the indentation rules and code style. And use 2 spaces, not tabs.
|
385
|
+
And don't touch the version thing.
|
353
386
|
|
354
387
|
## Configuring environment
|
355
388
|
|
356
|
-
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.
|
357
391
|
|
358
392
|
To run tests, execute `./bin/rake`.
|
359
393
|
|
360
394
|
### Adding new features
|
361
395
|
|
362
|
-
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.
|
363
398
|
|
364
399
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
365
400
|
|
366
401
|
#### Adding a new bot
|
367
402
|
|
368
403
|
1. Add the user agent to `test/ua_bots.yml`.
|
369
|
-
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.
|
370
406
|
3. Run tests.
|
371
407
|
|
372
408
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
@@ -375,42 +411,43 @@ Don't forget to add a new entry to `CHANGELOG.md`.
|
|
375
411
|
|
376
412
|
1. Add the user agent to `test/ua_search_engines.yml`.
|
377
413
|
2. Add the same user agent to `test/ua_bots.yml`.
|
378
|
-
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.
|
379
416
|
4. Run tests.
|
380
417
|
|
381
418
|
Don't forget to add a new entry to `CHANGELOG.md`.
|
382
419
|
|
383
420
|
#### Wrong browser/platform/device detection
|
384
421
|
|
385
|
-
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.
|
386
425
|
|
387
426
|
## Maintainer
|
388
427
|
|
389
|
-
|
428
|
+
- Nando Vieira - http://nandovieira.com
|
390
429
|
|
391
430
|
## Contributors
|
392
431
|
|
393
|
-
|
432
|
+
- https://github.com/fnando/browser/contributors
|
394
433
|
|
395
434
|
## License
|
396
435
|
|
397
436
|
(The MIT License)
|
398
437
|
|
399
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
IN
|
414
|
-
|
415
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
416
|
-
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.
|