From 22d2271e88af1d0eea22e25ae4ce841ae7408dbb Mon Sep 17 00:00:00 2001 From: Ankur Patel Date: Mon, 28 Oct 2024 20:49:25 -0700 Subject: [PATCH] Adding fix for Chrome Lighthouse not being detected as a bot --- lib/user_agent/browsers/base.rb | 4 ++++ spec/browsers/chrome_lighthouse_user_agent_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 spec/browsers/chrome_lighthouse_user_agent_spec.rb diff --git a/lib/user_agent/browsers/base.rb b/lib/user_agent/browsers/base.rb index eda5a11..86e5e9d 100644 --- a/lib/user_agent/browsers/base.rb +++ b/lib/user_agent/browsers/base.rb @@ -78,6 +78,10 @@ def bot? # list will be rejected. elsif detect_comment_match(/bot/i) true + # Google PageSpeed Insights adds "Chrome-Lighthouse" to the user agent + # https://stackoverflow.com/questions/16403295/what-is-the-name-of-the-google-pagespeed-user-agent + elsif detect_product("Chrome-Lighthouse") + true elsif product = application.product product.include?('bot') else diff --git a/spec/browsers/chrome_lighthouse_user_agent_spec.rb b/spec/browsers/chrome_lighthouse_user_agent_spec.rb new file mode 100644 index 0000000..5f54d4a --- /dev/null +++ b/spec/browsers/chrome_lighthouse_user_agent_spec.rb @@ -0,0 +1,9 @@ +require 'user_agent' + +describe "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4590.2 Safari/537.36 Chrome-Lighthouse" do + before do + @useragent = UserAgent.parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4590.2 Safari/537.36 Chrome-Lighthouse") + end + + it { expect(@useragent).to be_bot } +end