faisalman / ua-parser-js Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Oculus Quest and Oculus Quest 2, as well as another test for Oculus Browser #528
Conversation
Hi @jparismorgan thanks for contributing.
Rather than creating regex for each device, I prefer to use one regex that can catch them all, something like
/(quest( 2)?)/
Using this method, whenever 'Quest 3' or later released, we don't have to create yet another line of regex, instead we can just change it to
/(quest( \d)?)/
and since the 'Quest' / 'Quest 2' string is already in the user agent, it will be automatically captured so we don't have to retype it again
[MODEL], [VENDOR, FACEBOOK], [TYPE, WEARABLE]
Great, thanks @faisalman, updated to use a single line regex. Confirmed the tests still pass:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (updated) pattern results in a false positive when user agent string contains the string "quest", e.g. python-requests/2.24.0
, causing this to be incorrectly categorised a an Oculus Quest wearable.
(regex 1) A likely better pattern would be /\;\s?(Quest\s?\d{0,})/i
as it takes into account future versions as well + doesn't result in the false positive as pattern matches ;quest
and ; quest 2
and ; quest 23
and ;quest 12345
but NOT request
or conquest
or similar (i flag if you want it to be case insensitive)
(regex 2) Alternatively (and likely slightly better), if you don't want it to match ; Quest234
, this pattern will do: /\;\s?(Quest\s\d{0,}|Quest)/i
Thoughts/reflections: Technically, the pattern should only be matching if the string contains both "quest" and "oculus", right? Something like /(quest.*?)\).*?oculus.*/i
UA strings I've tested against using both the first and second regex:
Mozilla/5.0 (X11; Linux x86_64; Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36
- MATCH
Mozilla/5.0 (X11; Linux x86_64; Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36
- MATCH
Mozilla/5.0 (X11; Linux x86_64; Quest 23) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36
- MATCH
Mozilla/5.0 (X11; Linux x86_64;Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36
- MATCH
Mozilla/5.0 (X11; Linux x86_64;Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36
- MATCH
Mozilla/5.0 (X11; Linux x86_64;Quest 23) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36
- MATCH
Mozilla/5.0 (X11; Linux x86_64;Quest23) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/16.6.0.1.52.314146309 SamsungBrowser/4.0 Chrome/91.0.4472.164 Safari/537.36
- MATCH with regex 1 / NO MATCH with regex 2
python-requests/2.24.0
- NO MATCH
On a side note, I haven't yet figured out how I can override the built-in pattern. If I use the extend feature to add a "device" pattern for the python-requests/2.24.0
UA string, the "Oculus Quest" pattern still takes effect (overrides my pattern).
What
Based on https://developer.oculus.com/documentation/web/browser-specs/, which says:
we:
Open questions
"model": "Quest"
and"model": "Quest 2",
- is that what we want? Couldn't find much online about it.Testing
Tests pass:
The text was updated successfully, but these errors were encountered: