Update application_controller.rb

This commit is contained in:
TianLun Song 2025-01-27 07:40:13 +08:00 committed by GitHub
parent 70f977cae1
commit 75cdd69b9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,45 @@ class ApplicationController < ActionController::Base
include SeoConcern include SeoConcern
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
# allow_browser versions: :modern # allow_browser versions: :modern
allow_browser do |config|
# 保留现代浏览器支持
config.use :modern
# 通用移动浏览器
config.allow(/Mobile Safari/) # iOS Safari
config.allow(/Chrome\/[\d.]+/) # Chrome 内核浏览器
# 国内主流浏览器
config.allow(/Quark\/[\d.]+/) # 夸克浏览器
config.allow(/HuaweiBrowser\/[\d.]+/) # 华为浏览器
config.allow(/MiuiBrowser\/[\d.]+/) # 小米浏览器
config.allow(/VivoBrowser\/[\d.]+/) # vivo浏览器
config.allow(/OppoBrowser\/[\d.]+/) # OPPO浏览器
config.allow(/UCBrowser\/[\d.]+/) # UC浏览器
config.allow(/QQBrowser\/[\d.]+/) # QQ浏览器
config.allow(/MicroMessenger\/[\d.]+/) # 微信内置浏览器
config.allow(/Alipay/) # 支付宝内置浏览器
config.allow(/BaiduBoxApp/) # 百度 App
config.allow(/baiduboxapp/i) # 百度 App (小写)
config.allow(/SogouMobile/) # 搜狗移动浏览器
config.allow(/Weibo/) # 微博内置浏览器
config.allow(/DingTalk/) # 钉钉内置浏览器
config.allow(/ToutiaoMicroApp/) # 今日头条小程序
config.allow(/BytedanceWebview/) # 字节跳动系浏览器
config.allow(/ArkWeb/) # 鸿蒙浏览器
# 调试日志(开发环境)
if Rails.env.development?
config.on_failure do |browser|
Rails.logger.info <<~INFO
Browser blocked:
Name: #{browser.name}
Version: #{browser.version}
User Agent: #{browser.ua}
INFO
end
end
end
before_action :set_locale before_action :set_locale
after_action :track_action after_action :track_action