BrowserX
A drop-in replacement for the browser gem: same Browser namespace, same require "browser", same predicates. Change one line of the Gemfile, keep every call site.
gem "browserx"
In numbers
Measured by bench/request.rb on Ruby 4.0.9 with YJIT: what a web request asks (name, version, bot?, platform, device, accept-language), median of 7.
What changes
Nothing in your code
Every predicate, every require path and the Browser namespace of browser keep working unchanged. The upstream test suite runs unmodified.
Bot detection in one pass
The bot list is matched by one prefix-trie regexp instead of one match per entry, and the browser is no longer detected twice to answer bot?.
The same answers, proven
A snapshot script runs both gems over 20,328 user agents and a diff script compares them, so a speed-up cannot change a single answer unnoticed.
Half the allocations
Platform and device matchers are built lazily, only when a request asks for them.
A bot list meant to stay fresh
From permissively licensed sources: crawler-user-agents and ai.robots.txt, both MIT.
Current Ruby and Rails
Ruby 3.3 or later, tested on Rails 8.0 and 8.1. Bundler’s auto-require loads the gem, and the railtie no longer needs a preloaded ActiveSupport.
Quick start
Gemfile
gem "browserx" # instead of gem "browser"
Ruby
require "browser"
browser = Browser.new(user_agent, accept_language: "en-us")
browser.chrome?
browser.bot?
browser.device.mobile?