device_detector
Version, currently 0.4.01 version
- 0.4.0latestAug 4, 2025
github.com/crystal-garage/device_detector
Device detection library will parse User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), vendor and model.
Installation
# Add this to your shard.yml
dependencies:
device_detector:
github: crystal-garage/device_detector
version: ~> 0.4.0Then run:
shards installshard.yml
- Crystal
1.2.0- License
- MIT
- Authors
- creadone, delef, mamantoha
Dependencies
Runtime Dependencies
- baked_file_system*github: schovi/baked_file_system
README
Device Detector
The library for parsing User Agent and browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), vendor and model detection.
- Support latest Crystal version and update script for private use or immediately updates.
- Currently it is production version and works fine more that 2 years.
- The Library uses regexes from matomo-org/device-detector.
Installation
Add this to your application's shard.yml:
dependencies:
device_detector:
github: crystal-garage/device_detector
Then run shards install
Usage
require "device_detector"
user_agent = "Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 Edge/12.0"
response = DeviceDetector::Detector.new(user_agent).call # All parsers
response = DeviceDetector::Detector.new(user_agent).lite # Only for bot and mobile
# Check if browser detected
response.browser? #=> true
# browser name
response.browser_name #=> Microsoft Edge
# browser version
response.browser_version #=> 12.0
# get raw response with
pp response.raw
[{
"bot" => {
"name" => ""
}
},
{
"browser" => {
"name" => "", "version" => ""
}
},
{...},
{
"vendorfragment" => {
"vendor" => ""
}
}
]
Available methods:
Benchmark
crystal run ./bench/raw_response.cr --release
Results:
user system total real
full: 1.645194 0.025706 1.670900 ( 1.677467)
lite: 0.766103 0.007790 0.773893 ( 0.777249)
It's mean that device_detector can work with 1000 / 1.68 ~ 595 QPS (full) and 1000 / 0.78 ~ 1282 QPS (lite).
Note: This benchmark uses 20 diverse user agents including browsers, mobile devices, and bots for realistic performance measurement.
Testing
crystal spec
Update regexes
crystal scripts/update_regexes.cr
ToDo
- Support overloading of base rules
- CLI & HTTP version
- More lighter and faster the
liteversion - Reload regexes on the fly (may be)
Contributing
- Fork it ( https://github.com/crystal-garage/device_detector/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- @creadone Sergey Fedorov - creator, maintainer
- @delef Ivan Palamarchuk - new api, code optimization
- @zaycker Yuriy Zaitsev - fix check order
- @mamantoha Anton Maminov - maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.4.0- Tagged
- Aug 4, 2025
- Commit
985a772611a5- Crystal
1.2.0- Indexed
- yes
Dependents
Repository
github.com/crystal-garage/device_detector
Metadata
- Created
- Aug 16, 2026
- Updated
- Sep 24, 2026
- Synced
- Sep 24, 2026
- Versions
- 1