Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add epiphany (gnome web) browser detection. #552

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

- Add `Browser::Base#epiphany?`.
- Don't ever match linux-based browsers as Safari.

## 6.1.0

- Add more bots (mostly related to AI crawlers)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ browser.qq?
browser.weibo?
browser.sputnik?
browser.sougou_browser?
browser.epiphany?

# Get bot info
browser.bot.name
Expand Down
5 changes: 5 additions & 0 deletions lib/browser/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ def electron?(expected_version = nil)
instance_of?(Electron) && detect_version?(full_version, expected_version)
end

# Detect if the browser is Epiphany.
def epiphany?(expected_version = nil)
instance_of?(Epiphany) && detect_version?(full_version, expected_version)
end

private def validate_size(subject, input)
actual_bytesize = input.bytesize
size_limit = Browser.public_send(:"#{subject}_size_limit")
Expand Down
38 changes: 21 additions & 17 deletions lib/browser/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
require_relative "maxthon"
require_relative "sougou_browser"
require_relative "google_search_app"
require_relative "epiphany"

require_relative "bot"
require_relative "bot/empty_user_agent_matcher"
Expand Down Expand Up @@ -77,23 +78,26 @@ def self.matchers
InternetExplorer,
Firefox,
Otter,
Facebook, # must be placed before Chrome and Safari
Instagram, # must be placed before Chrome and Safari
Snapchat, # must be placed before Chrome and Safari
Weibo, # must be placed before Chrome and Safari
MicroMessenger, # must be placed before QQ
QQ, # must be placed before Chrome and Safari
Alipay, # must be placed before Chrome and Safari
Electron, # must be placed before Chrome and Safari
Yandex, # must be placed before Chrome and Safari
Sputnik, # must be placed before Chrome and Safari
DuckDuckGo, # must be placed before Chrome and Safari
SamsungBrowser, # must be placed before Chrome and Safari
HuaweiBrowser, # must be placed before Chrome and Safari
MiuiBrowser, # must be placed before Chrome and Safari
Maxthon, # must be placed before Chrome and Safari
SougouBrowser, # must be placed before Chrome and Safari
GoogleSearchApp, # must be placed before Chrome and Safari
Epiphany,
Facebook,
Instagram,
Snapchat,
Weibo,
MicroMessenger, # must be placed before QQ
QQ,
Alipay,
Electron,
Yandex,
Sputnik,
DuckDuckGo,
SamsungBrowser,
HuaweiBrowser,
MiuiBrowser,
Maxthon,
SougouBrowser,
GoogleSearchApp,

# Must be last
Chrome,
Safari,
Unknown
Expand Down
21 changes: 21 additions & 0 deletions lib/browser/epiphany.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Browser
class Epiphany < Base
def id
:epiphany
end

def name
"Epiphany"
end

def full_version
ua[%r{Epiphany/([\d.]+)}, 1] || "0.0"
end

def match?
ua.include?("Epiphany")
end
end
end
1 change: 1 addition & 0 deletions lib/browser/safari.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def full_version

def match?
ua.include?("Safari") &&
!platform.linux? &&
!ua.match?(/PhantomJS|FxiOS/) &&
!edge? &&
!chrome? &&
Expand Down
1 change: 1 addition & 0 deletions test/ua.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CUSTOM_APP: "Our App 0.0.1 (Linux; Android 4.0.3; HTC Ruby Build/IML74K; en_CA)"
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"
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"
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"
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"
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]
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;]"
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]"
Expand Down
21 changes: 21 additions & 0 deletions test/unit/epiphany_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "test_helper"

class EpiphanyBrowserTest < Minitest::Test
test "detects epiphany browser" do
browser = Browser.new(Browser["EPIPHANY"])

assert browser.epiphany?
refute browser.safari?
assert_equal "Epiphany", browser.name
assert_equal :epiphany, browser.id
assert_equal "3.18.11", browser.full_version
assert_equal "3", browser.version
end

test "detects version by range" do
browser = Browser.new(Browser["EPIPHANY"])
assert browser.epiphany?(%w[=3.18.11])
end
end
Loading