The user-agent-utils java library can be used to parse HTTP requests in real-time or to analyze log files and gather information about the user-agent.
Warning: This project is end-of-life and does not get updated any longer!
As alternative have a look at the Browscap project and its implementations.
Fast detection of:
- more than 150 different browsers
- 7 different browser types
- more than 60 different operating systems
- 6 different device types
- 9 different rendering engines
- 9 different web applications
By not trying to identify hundreds or even thousands of different clients and operating systems it tries to offer a compromise between performance and usability. Other libraries (some commercial) offer a more detailed detection.
For the latest release, go to https://github.com/HaraldWalker/user-agent-utils/tree/release-1.21
For the latest snapshot version, go to https://github.com/HaraldWalker/user-agent-utils
If you need more frequent updates, using the snapshot version is another option:
<dependency> <groupId>eu.bitwalker</groupId> <artifactId>UserAgentUtils</artifactId> <version>1.22-SNAPSHOT</version> </dependency>
Pass the user-agent string from the request as parameter to the parser.
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
Can I add new browsers or operating systems?
Unfortunately not directly. This library uses enums to represent browsers and operating systems to make using it easy and readable. Unfortunately the use of enums also has some disadvantages.
You can make a pull request on trunk for a new browser or operating system if all tests are still passing. The purpose of this library was and is not to detect every possible version.
Where can I report bugs or make feature requests?
This project is not accepting issues or change requests any longer. Feel free to fork it, make your own changes and release updates yourself.
When handling requests on a web-server, consider if you need both the browser and operating system or if one of the two gives you enough information. As the parsing uses an ordered tree structure, performance depends a lot on the type of clients making the requests. The most common browsers and operating systems will be parsed faster than exotic ones. Consider caching the results temporarily.
When I started this project in 2010 there were no other libraries offering the features I was looking for. Currently there are both open source as well as commercial solutions.
Should I use this library for my web-project?