browser 4.1.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +57 -0
  3. data/.rubocop.yml +3 -0
  4. data/CHANGELOG.md +46 -3
  5. data/FUNDING.yml +3 -0
  6. data/README.md +101 -50
  7. data/bots.yml +299 -298
  8. data/browser.gemspec +5 -4
  9. data/lib/browser/accept_language.rb +4 -4
  10. data/lib/browser/alipay.rb +1 -1
  11. data/lib/browser/base.rb +72 -13
  12. data/lib/browser/blackberry.rb +1 -1
  13. data/lib/browser/bot/keyword_matcher.rb +1 -1
  14. data/lib/browser/browser.rb +21 -2
  15. data/lib/browser/chrome.rb +9 -3
  16. data/lib/browser/device.rb +12 -5
  17. data/lib/browser/device/android.rb +1 -1
  18. data/lib/browser/device/blackberry_playbook.rb +1 -1
  19. data/lib/browser/device/ipad.rb +1 -1
  20. data/lib/browser/device/iphone.rb +1 -1
  21. data/lib/browser/device/ipod_touch.rb +1 -1
  22. data/lib/browser/device/kindle.rb +1 -1
  23. data/lib/browser/device/kindle_fire.rb +1 -1
  24. data/lib/browser/device/playstation3.rb +1 -1
  25. data/lib/browser/device/playstation4.rb +1 -1
  26. data/lib/browser/device/psp.rb +1 -1
  27. data/lib/browser/device/psvita.rb +1 -1
  28. data/lib/browser/device/samsung.rb +33 -0
  29. data/lib/browser/device/surface.rb +1 -1
  30. data/lib/browser/device/switch.rb +1 -1
  31. data/lib/browser/device/tv.rb +1 -1
  32. data/lib/browser/device/unknown.rb +1 -1
  33. data/lib/browser/device/wii.rb +1 -1
  34. data/lib/browser/device/wiiu.rb +1 -1
  35. data/lib/browser/device/xbox_360.rb +1 -1
  36. data/lib/browser/device/xbox_one.rb +1 -1
  37. data/lib/browser/duck_duck_go.rb +1 -1
  38. data/lib/browser/edge.rb +2 -2
  39. data/lib/browser/electron.rb +1 -1
  40. data/lib/browser/facebook.rb +1 -1
  41. data/lib/browser/firefox.rb +1 -1
  42. data/lib/browser/google_search_app.rb +21 -0
  43. data/lib/browser/huawei_browser.rb +21 -0
  44. data/lib/browser/instagram.rb +1 -1
  45. data/lib/browser/internet_explorer.rb +2 -2
  46. data/lib/browser/maxthon.rb +21 -0
  47. data/lib/browser/micro_messenger.rb +1 -1
  48. data/lib/browser/miui_browser.rb +21 -0
  49. data/lib/browser/nokia.rb +1 -1
  50. data/lib/browser/opera.rb +1 -1
  51. data/lib/browser/otter.rb +1 -1
  52. data/lib/browser/phantom_js.rb +1 -1
  53. data/lib/browser/platform.rb +21 -15
  54. data/lib/browser/platform/adobe_air.rb +1 -1
  55. data/lib/browser/platform/android.rb +1 -1
  56. data/lib/browser/platform/blackberry.rb +1 -1
  57. data/lib/browser/platform/chrome_os.rb +1 -1
  58. data/lib/browser/platform/firefox_os.rb +1 -1
  59. data/lib/browser/platform/ios.rb +2 -2
  60. data/lib/browser/platform/kai_os.rb +23 -0
  61. data/lib/browser/platform/linux.rb +1 -1
  62. data/lib/browser/platform/mac.rb +2 -2
  63. data/lib/browser/platform/{other.rb → unknown.rb} +3 -3
  64. data/lib/browser/platform/windows.rb +2 -2
  65. data/lib/browser/platform/windows_mobile.rb +1 -1
  66. data/lib/browser/platform/windows_phone.rb +1 -1
  67. data/lib/browser/qq.rb +1 -1
  68. data/lib/browser/safari.rb +12 -3
  69. data/lib/browser/samsung_browser.rb +1 -1
  70. data/lib/browser/snapchat.rb +1 -1
  71. data/lib/browser/sougou_browser.rb +24 -0
  72. data/lib/browser/sputnik.rb +1 -1
  73. data/lib/browser/uc_browser.rb +1 -1
  74. data/lib/browser/{generic.rb → unknown.rb} +3 -3
  75. data/lib/browser/version.rb +1 -1
  76. data/lib/browser/weibo.rb +1 -1
  77. data/lib/browser/yandex.rb +1 -1
  78. data/samsung.yml +138 -0
  79. data/test/browser_test.rb +37 -6
  80. data/test/ua.yml +18 -4
  81. data/test/ua_bots.yml +3 -2
  82. data/test/unit/adobe_air_test.rb +1 -1
  83. data/test/unit/alipay_test.rb +6 -0
  84. data/test/unit/bots_test.rb +1 -1
  85. data/test/unit/console_test.rb +2 -2
  86. data/test/unit/device_test.rb +30 -3
  87. data/test/unit/duck_duck_go_test.rb +2 -0
  88. data/test/unit/google_search_app_test.rb +54 -0
  89. data/test/unit/huawei_browser_test.rb +25 -0
  90. data/test/unit/kai_os_test.rb +31 -0
  91. data/test/unit/maxthon_test.rb +25 -0
  92. data/test/unit/meta_test.rb +10 -1
  93. data/test/unit/miui_browser_test.rb +25 -0
  94. data/test/unit/opera_test.rb +1 -0
  95. data/test/unit/platform_test.rb +7 -7
  96. data/test/unit/qq_test.rb +12 -0
  97. data/test/unit/safari_test.rb +12 -7
  98. data/test/unit/samsung_browser_test.rb +1 -0
  99. data/test/unit/sougou_browser_test.rb +41 -0
  100. metadata +37 -16
  101. data/.travis.yml +0 -23
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /PLAYSTATION 4/i
15
+ ua.match?(/PLAYSTATION 4/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /PlayStation Portable/
15
+ ua.include?("PlayStation Portable")
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Playstation Vita/
15
+ ua.match?("Playstation Vita")
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class Device
5
+ class Samsung < Base
6
+ REGEX = /\(Linux.*?; Android.*?; (SAMSUNG )?(SM-[A-Z0-9]+).*?\)/i.freeze
7
+
8
+ def self.names
9
+ @names ||= YAML.load_file(Browser.root.join("samsung.yml").to_s)
10
+ end
11
+
12
+ def id
13
+ :samsung
14
+ end
15
+
16
+ def name
17
+ "Samsung #{self.class.names[code] || code}"
18
+ end
19
+
20
+ def code
21
+ matches && matches[2]
22
+ end
23
+
24
+ def matches
25
+ @matches ||= ua.match(REGEX)
26
+ end
27
+
28
+ def match?
29
+ !!matches
30
+ end
31
+ end
32
+ end
33
+ end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- platform.windows_rt? && ua =~ /Touch/
15
+ platform.windows_rt? && ua.include?("Touch")
16
16
  end
17
17
 
18
18
  private def platform
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Nintendo Switch/i
15
+ ua.match?(/Nintendo Switch/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /(\btv|Android.*?ADT-1|Nexus Player)/i
15
+ ua.match?(/(\btv|Android.*?ADT-1|Nexus Player)/i)
16
16
  end
17
17
  end
18
18
  end
@@ -4,7 +4,7 @@ module Browser
4
4
  class Device
5
5
  class Unknown < Base
6
6
  def id
7
- :unknown
7
+ :unknown_device
8
8
  end
9
9
 
10
10
  def name
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Nintendo Wii/i
15
+ ua.match?(/Nintendo Wii/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Nintendo WiiU/i
15
+ ua.match?(/Nintendo WiiU/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Xbox/i
15
+ ua.match?(/Xbox/i)
16
16
  end
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module Browser
12
12
  end
13
13
 
14
14
  def match?
15
- ua =~ /Xbox One/i
15
+ ua.match?(/Xbox One/i)
16
16
  end
17
17
  end
18
18
  end
@@ -16,7 +16,7 @@ module Browser
16
16
  end
17
17
 
18
18
  def match?
19
- ua =~ /DuckDuckGo/
19
+ ua.include?("DuckDuckGo")
20
20
  end
21
21
  end
22
22
  end
@@ -15,11 +15,11 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ %r{((?:Edge|Edg|EdgiOS|EdgA)/[\d.]+|Trident/8)}
18
+ ua.match?(%r{((?:Edge|Edg|EdgiOS|EdgA)/[\d.]+|Trident/8)})
19
19
  end
20
20
 
21
21
  def chrome_based?
22
- match? && ua =~ /\bEdg\b/
22
+ match? && ua.match?(/\bEdg\b/)
23
23
  end
24
24
  end
25
25
  end
@@ -16,7 +16,7 @@ module Browser
16
16
  end
17
17
 
18
18
  def match?
19
- ua =~ /Electron/
19
+ ua.include?("Electron")
20
20
  end
21
21
  end
22
22
  end
@@ -17,7 +17,7 @@ module Browser
17
17
  end
18
18
 
19
19
  def match?
20
- ua =~ /FBAV|FBAN/
20
+ ua.match?(/FBAV|FBAN/)
21
21
  end
22
22
  end
23
23
  end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /Firefox|FxiOS/
18
+ ua.match?(/Firefox|FxiOS/)
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class GoogleSearchApp < Chrome
5
+ def id
6
+ :google_search_app
7
+ end
8
+
9
+ def name
10
+ "Google Search App"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{GSA/([\d.]+\d)}, 1] || super
15
+ end
16
+
17
+ def match?
18
+ ua.include?("GSA")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class HuaweiBrowser < Base
5
+ def id
6
+ :huawei_browser
7
+ end
8
+
9
+ def name
10
+ "Huawei Browser"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{(?:HuaweiBrowser)/([\d.]+)}i, 1] || "0.0"
15
+ end
16
+
17
+ def match?
18
+ ua.match?(/HuaweiBrowser/i)
19
+ end
20
+ end
21
+ end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /Instagram/
18
+ ua.include?("Instagram")
19
19
  end
20
20
  end
21
21
  end
@@ -52,11 +52,11 @@ module Browser
52
52
  end
53
53
 
54
54
  private def msie?
55
- ua =~ /MSIE/ && ua !~ /Opera/
55
+ ua.include?("MSIE") && !ua.include?("Opera")
56
56
  end
57
57
 
58
58
  private def modern_ie?
59
- ua =~ %r{Trident/.*?; rv:(.*?)}
59
+ ua.match?(%r{Trident/.*?; rv:(.*?)})
60
60
  end
61
61
  end
62
62
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class Maxthon < Base
5
+ def id
6
+ :maxthon
7
+ end
8
+
9
+ def name
10
+ "Maxthon"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{(?:Maxthon)/([\d.]+)}i, 1] || "0.0"
15
+ end
16
+
17
+ def match?
18
+ ua.match?(/Maxthon/i)
19
+ end
20
+ end
21
+ end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /MicroMessenger/i
18
+ ua.match?(/MicroMessenger/i)
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Browser
4
+ class MiuiBrowser < Base
5
+ def id
6
+ :miui_browser
7
+ end
8
+
9
+ def name
10
+ "Miui Browser"
11
+ end
12
+
13
+ def full_version
14
+ ua[%r{MiuiBrowser/([\d.]+)}, 1] || "0.0"
15
+ end
16
+
17
+ def match?
18
+ ua.include?("MiuiBrowser")
19
+ end
20
+ end
21
+ end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /S40OviBrowser/
18
+ ua.include?("S40OviBrowser")
19
19
  end
20
20
  end
21
21
  end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ %r{(Opera|OPR/)}
18
+ ua.match?(%r{(Opera|OPR/)})
19
19
  end
20
20
  end
21
21
  end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /Otter/
18
+ ua.include?("Otter")
19
19
  end
20
20
  end
21
21
  end
@@ -15,7 +15,7 @@ module Browser
15
15
  end
16
16
 
17
17
  def match?
18
- ua =~ /PhantomJS/
18
+ ua.include?("PhantomJS")
19
19
  end
20
20
  end
21
21
  end
@@ -10,9 +10,10 @@ require_relative "platform/windows_mobile"
10
10
  require_relative "platform/firefox_os"
11
11
  require_relative "platform/blackberry"
12
12
  require_relative "platform/android"
13
- require_relative "platform/other"
13
+ require_relative "platform/unknown"
14
14
  require_relative "platform/chrome_os"
15
15
  require_relative "platform/adobe_air"
16
+ require_relative "platform/kai_os"
16
17
 
17
18
  module Browser
18
19
  class Platform
@@ -32,10 +33,11 @@ module Browser
32
33
  BlackBerry,
33
34
  IOS,
34
35
  Mac,
36
+ KaiOS,
35
37
  FirefoxOS,
36
38
  Windows,
37
39
  Linux,
38
- Other
40
+ Unknown
39
41
  ]
40
42
  end
41
43
 
@@ -61,8 +63,8 @@ module Browser
61
63
  id == :android && detect_version?(version, expected_version)
62
64
  end
63
65
 
64
- def other?
65
- id == :other
66
+ def unknown?
67
+ id == :unknown_platform
66
68
  end
67
69
 
68
70
  def linux?
@@ -81,6 +83,10 @@ module Browser
81
83
  id == :firefox_os
82
84
  end
83
85
 
86
+ def kai_os?
87
+ id == :kai_os
88
+ end
89
+
84
90
  def ios?(expected_version = nil)
85
91
  id == :ios && detect_version?(version, expected_version)
86
92
  end
@@ -130,46 +136,46 @@ module Browser
130
136
  # Detect if in an Android app webview (Lollipop and newer)
131
137
  # https://developer.chrome.com/multidevice/user-agent#webview_user_agent
132
138
  def android_app?
133
- android? && ua =~ /\bwv\b/
139
+ android? && ua.match?(/\bwv\b/)
134
140
  end
135
141
  alias_method :android_webview?, :android_app?
136
142
 
137
143
  # http://msdn.microsoft.com/fr-FR/library/ms537503.aspx#PltToken
138
144
  def windows_xp?
139
- windows? && ua =~ /Windows NT 5\.[12]/
145
+ windows? && ua.match?(/Windows NT 5\.[12]/)
140
146
  end
141
147
 
142
148
  def windows_vista?
143
- windows? && ua =~ /Windows NT 6\.0/
149
+ windows? && ua.include?("Windows NT 6.0")
144
150
  end
145
151
 
146
152
  def windows7?
147
- windows? && ua =~ /Windows NT 6\.1/
153
+ windows? && ua.include?("Windows NT 6.1")
148
154
  end
149
155
 
150
156
  def windows8?
151
- windows? && ua =~ /Windows NT 6\.[2-3]/
157
+ windows? && ua.match?(/Windows NT 6\.[2-3]/)
152
158
  end
153
159
 
154
160
  def windows8_1?
155
- windows? && ua =~ /Windows NT 6\.3/
161
+ windows? && ua.include?("Windows NT 6.3")
156
162
  end
157
163
 
158
164
  def windows10?
159
- windows? && ua =~ /Windows NT 10/
165
+ windows? && ua.include?("Windows NT 10")
160
166
  end
161
167
 
162
168
  def windows_rt?
163
- windows8? && ua =~ /ARM/
169
+ windows8? && ua.include?("ARM")
164
170
  end
165
171
 
166
172
  # Detect if current platform is Windows in 64-bit architecture.
167
173
  def windows_x64?
168
- windows? && ua =~ /(Win64|x64|Windows NT 5\.2)/
174
+ windows? && ua.match?(/(Win64|x64|Windows NT 5\.2)/)
169
175
  end
170
176
 
171
177
  def windows_wow64?
172
- windows? && ua =~ /WOW64/i
178
+ windows? && ua.match?(/WOW64/i)
173
179
  end
174
180
 
175
181
  def windows_x64_inclusive?
@@ -177,7 +183,7 @@ module Browser
177
183
  end
178
184
 
179
185
  def windows_touchscreen_desktop?
180
- windows? && ua =~ /Touch/
186
+ windows? && ua.include?("Touch")
181
187
  end
182
188
 
183
189
  private :subject