Skip to content

Commit 6e9b7be

Browse files
authored
Add epiphany (gnome web) browser detection. (#552)
1 parent e71ee1b commit 6e9b7be

File tree

8 files changed

+76
-17
lines changed

8 files changed

+76
-17
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Add `Browser::Base#epiphany?`.
6+
- Don't ever match linux-based browsers as Safari.
7+
38
## 6.1.0
49

510
- Add more bots (mostly related to AI crawlers)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ browser.qq?
5555
browser.weibo?
5656
browser.sputnik?
5757
browser.sougou_browser?
58+
browser.epiphany?
5859

5960
# Get bot info
6061
browser.bot.name

lib/browser/base.rb

+5
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ def electron?(expected_version = nil)
268268
instance_of?(Electron) && detect_version?(full_version, expected_version)
269269
end
270270

271+
# Detect if the browser is Epiphany.
272+
def epiphany?(expected_version = nil)
273+
instance_of?(Epiphany) && detect_version?(full_version, expected_version)
274+
end
275+
271276
private def validate_size(subject, input)
272277
actual_bytesize = input.bytesize
273278
size_limit = Browser.public_send(:"#{subject}_size_limit")

lib/browser/browser.rb

+21-17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
require_relative "maxthon"
3838
require_relative "sougou_browser"
3939
require_relative "google_search_app"
40+
require_relative "epiphany"
4041

4142
require_relative "bot"
4243
require_relative "bot/empty_user_agent_matcher"
@@ -77,23 +78,26 @@ def self.matchers
7778
InternetExplorer,
7879
Firefox,
7980
Otter,
80-
Facebook, # must be placed before Chrome and Safari
81-
Instagram, # must be placed before Chrome and Safari
82-
Snapchat, # must be placed before Chrome and Safari
83-
Weibo, # must be placed before Chrome and Safari
84-
MicroMessenger, # must be placed before QQ
85-
QQ, # must be placed before Chrome and Safari
86-
Alipay, # must be placed before Chrome and Safari
87-
Electron, # must be placed before Chrome and Safari
88-
Yandex, # must be placed before Chrome and Safari
89-
Sputnik, # must be placed before Chrome and Safari
90-
DuckDuckGo, # must be placed before Chrome and Safari
91-
SamsungBrowser, # must be placed before Chrome and Safari
92-
HuaweiBrowser, # must be placed before Chrome and Safari
93-
MiuiBrowser, # must be placed before Chrome and Safari
94-
Maxthon, # must be placed before Chrome and Safari
95-
SougouBrowser, # must be placed before Chrome and Safari
96-
GoogleSearchApp, # must be placed before Chrome and Safari
81+
Epiphany,
82+
Facebook,
83+
Instagram,
84+
Snapchat,
85+
Weibo,
86+
MicroMessenger, # must be placed before QQ
87+
QQ,
88+
Alipay,
89+
Electron,
90+
Yandex,
91+
Sputnik,
92+
DuckDuckGo,
93+
SamsungBrowser,
94+
HuaweiBrowser,
95+
MiuiBrowser,
96+
Maxthon,
97+
SougouBrowser,
98+
GoogleSearchApp,
99+
100+
# Must be last
97101
Chrome,
98102
Safari,
99103
Unknown

lib/browser/epiphany.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
module Browser
4+
class Epiphany < Base
5+
def id
6+
:epiphany
7+
end
8+
9+
def name
10+
"Epiphany"
11+
end
12+
13+
def full_version
14+
ua[%r{Epiphany/([\d.]+)}, 1] || "0.0"
15+
end
16+
17+
def match?
18+
ua.include?("Epiphany")
19+
end
20+
end
21+
end

lib/browser/safari.rb

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def full_version
1919

2020
def match?
2121
ua.include?("Safari") &&
22+
!platform.linux? &&
2223
!ua.match?(/PhantomJS|FxiOS/) &&
2324
!edge? &&
2425
!chrome? &&

test/ua.yml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ CUSTOM_APP: "Our App 0.0.1 (Linux; Android 4.0.3; HTC Ruby Build/IML74K; en_CA)"
3636
DUCKDUCKGO_BROWSER_ANDROID: Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.96 Mobile Safari/537.36 DuckDuckGo/5"
3737
DUCKDUCKGO_BROWSER_IOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 DuckDuckGo/7"
3838
ELECTRON: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Electron/1.4.12 Safari/537.36"
39+
EPIPHANY: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Safari/605.1.15 Ubuntu/16.04 (3.18.11-0ubuntu1) Epiphany/3.18.11"
3940
FACEBOOK: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 [FBAN/FBIOS;FBAV/135.0.0.45.90;FBBV/66877072;FBDV/iPhone9,3;FBMD/iPhone;FBSN/iOS;FBSV/10.3.3;FBSS/2;FBCR/AT&T;FBID/phone;FBLC/en_US;FBOP/5;FBRV/0]
4041
FACEBOOK_ANDROID: "Mozilla/5.0 (Linux; Android 9; ONEPLUS A6003 Build/PKQ1.180716.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/73.0.3683.90 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/214.0.0.43.83;]"
4142
FACEBOOK_IOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 [FBAN/FBIOS;FBDV/iPhone11,2;FBMD/iPhone;FBSN/iOS;FBSV/12.1.4;FBSS/3;FBCR/KPN NL;FBID/phone;FBLC/en_GB;FBOP/5]"

test/unit/epiphany_test.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class EpiphanyBrowserTest < Minitest::Test
6+
test "detects epiphany browser" do
7+
browser = Browser.new(Browser["EPIPHANY"])
8+
9+
assert browser.epiphany?
10+
refute browser.safari?
11+
assert_equal "Epiphany", browser.name
12+
assert_equal :epiphany, browser.id
13+
assert_equal "3.18.11", browser.full_version
14+
assert_equal "3", browser.version
15+
end
16+
17+
test "detects version by range" do
18+
browser = Browser.new(Browser["EPIPHANY"])
19+
assert browser.epiphany?(%w[=3.18.11])
20+
end
21+
end

0 commit comments

Comments
 (0)