ua-parser / uap-ruby Goto Github PK
View Code? Open in Web Editor NEWA simple, comprehensive Ruby gem for parsing user agent strings with the help of BrowserScope's UA database
License: MIT License
A simple, comprehensive Ruby gem for parsing user agent strings with the help of BrowserScope's UA database
License: MIT License
The ability to support more that one regexes database file. (regexes should be any array of filenames)
The thought here is that one file would be the "standard" from https://github.com/tobie/ua-parser/blob/master/regexes.yaml and another might contain "custom" user agents. They could be appended to the standard by sections; user_agent_parsers, os_parsers, ,device_parsers.
The files should be "loaded" in order.
Also see the request for Logstash: https://logstash.jira.com/browse/LOGSTASH-1323
I tried two approaches for supporting both 1.9 and 1.8.7.
I'd like to use user_agent_parser in github/gollum, however 1.8 support is required. Any advice on converting yaml to a common format that can be shared between ruby versions and still pass the tests?
User Agent:
Mozilla/5.0 (Linux; Android 10; Redm Note 9S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Mobile Safari/537.36
'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0'
is returning : #<UserAgentParser::UserAgent IE 9.0 (Windows 7) (Other)>
Hi, can you give additional functionality to detect is UA string indicates a bot or not, something like ua.is_bot?
?? Or let me know if there's something like that built in..
The README gives the following example:
UserAgentParser.parse "Mozilla/5.0 (iPad; CPU OS 10_2_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) GSA/23.1.148956103 Mobile/14D27 Safari/600.1.4"
#=> <UserAgentParser::UserAgent Mobile Safari 10.2.1 (iOS 10.2.1) (iPad)>
however, with the current version (2.7.0), I'll a different browser:
UserAgentParser.parse "Mozilla/5.0 (iPad; CPU OS 10_2_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) GSA/23.1.148956103 Mobile/14D27 Safari/600.1.4"
#=> #<UserAgentParser::UserAgent Google 23.1.148956103 (iOS 10.2.1) (iPad)>
I've never seen a GSA/x.y.z
fragment, so I'm not sure what the correct output should be ("Google 23.1.148956103" or "Safari 10.2.1").
I believe the command-line util example has a typo in it?
$ cat SOME-FILE-WITH-USER-AGENTS.txt | user_agent_parser --format '%f %M' | distribution
Not sure what distribution
is supposed to be? Maybe grep distribution
?
https://rubygems.org/search?utf8=%E2%9C%93&query=useragent
Can be solved by adding "useragent" without spaces into the gem description
The git submodule in this repo still points at https://github.com/tobie/ua-parser, but per the README:
ua-parser has moved
This project has moved to a new project space ua-parser, separating the regexes from the parsers for the different languages into their own repos:
- uap-core : The regex file necessary to build language ports of Browserscope's user agent parser.
I figure this will probably be fixed the next time the gem is bumped to get an updated database (BTW, uap-core has updated since the last version of this gem), but I thought I'd make this issue explicit just in case. ;)
This:
$ irb
jruby-9.1.8.0 :001 > require 'user_agent_parser'
=> true
jruby-9.1.8.0 :002 > ua = UserAgentParser.parse('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome Safari/537.36')
=> #<UserAgentParser::UserAgent Safari (Linux) (Other)>
jruby-9.1.8.0 :003 > ua.to_s
=> "Safari"
jruby-9.1.8.0 :004 > ua.version
=> nil
The context is that we're using Capybara and headless Chrome to drive some testing. We record the parsed user agent in our tests and we get Safari
instead of something Chrome-like.
The original ua-parser spec includes an "os.family" option. Are there any plans for including os.family in this gem?
Great gem, one thing I had to do immediately was to build my own display format.
user_agent = UserAgentParser.parse 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0;)'
=> #<UserAgentParser::UserAgent IE 9.0 (Windows Vista)>
user_agent.to_s
=> "IE 9.0"
As per above (from the docs) to_s
is too brief for my liking - I actually prefer the inspect
formatting.
Wondering if we should add a to_fs
method or similar that maybe even has a couple of supported formats (inspired by Rails formatting of dates and times) e.g.
user_agent = UserAgentParser.parse "Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-G930T Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.0 Chrome/51.0.2704.106 Mobile Safari/537.36"
=> #<UserAgentParser::UserAgent Samsung Internet 5.0 (Android 7.0) (Samsung SM-G930T)>
user_agent.to_fs
=> "Samsung Internet 5.0 (Android 7.0)"
user_agent.to_fs(:short)
=> "Samsung Internet 5.0"
user_agent.to_fs(:medium)
=> "Samsung Internet 5.0 (Android 7.0)"
user_agent.to_fs(:long)
=> "Samsung Internet 5.0 (Android 7.0) (Samsung SM-G930T)"
Open to different format suggestions.
Another option would be similar to timestamp formatting "YYYY-MM-DD HH:MM:SS Z"
where we had a formatting string such as "F V (O) (D)"
but that seems more confusing than helpful and doesn't deal well with optionally present information.
I see you marked the new version in the gemspec, but it isn't pushed to rubygems yet. Anything you are waiting on that I can help with?
We want to use https://www.npmjs.com/package/react-native-user-agent in our app and use this gem to detect the UA, however we discovered that Android application name is not properly detected.
UserAgentParser.parse 'application-name/1.6.7.42 Dalvik/2.1.0 (Linux; U; Android 5.1.1; Android SDK built for x86 Build/LMY48X)'
=> #<UserAgentParser::UserAgent Android 5.1.1 (Android 5.1.1) (Android SDK built for x86)>
but should be
#<UserAgentParser::UserAgent application-name 1.6.7.42 (Android 5.1.1) (Android SDK built for x86)>
On iOS however everything works properly:
UserAgentParser.parse 'application-name/1.6.4.176 CFNetwork/897.15 Darwin/17.5.0 (iPhone/6s iOS/11.3)'
=> #<UserAgentParser::UserAgent application-name 1.6.4.176 (iOS 11.3) (iPhone)>
Could you fix this please?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.