The Wayback Machine - https://web.archive.org/web/20211118155302/https://github.com/faisalman/ua-parser-js/pull/528
Skip to content
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

Merged
merged 5 commits into from Oct 6, 2021

Conversation

@jparismorgan
Copy link
Contributor

@jparismorgan jparismorgan commented Sep 21, 2021

What

Based on https://developer.oculus.com/documentation/web/browser-specs/, which says:

The user-agent (UA) string for Oculus Browser is:

Mozilla/5.0 (Linux; Android 10; Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/15.0.0.0.22.280317669 SamsungBrowser/4.0 Chrome/89.0.4389.90 VR Safari/537.36

The UA string should not be used for feature detection. The UA string token for Oculus Quest devices is “Quest” and Oculus Quest 2 is “Quest 2”. Oculus Browser allows users to switch into mobile mode, in which case the “VR” token above becomes “Mobile VR”. Note the Browser and Chromium version numbers may be newer than stated above.

we:

  • Add device model detection of Oculus Quest and Oculus Quest 2.
  • Add their provided user agent as a unit test in the Oculus Browser detection page. This doesn't require any changes to the detection, but thought it was useful to still add as a regression test. But happy to remove if you'd like.

Open questions

  • I used "model": "Quest" and "model": "Quest 2", - is that what we want? Couldn't find much online about it.
  • Is there a better regex we would prefer for Oculus Quest and Oculus Quest 2? I just did very basic string matching..

Testing

Tests pass:

~/repo/ua-parser-jparismorgan$ npm run test                                                                                                                                                                                                                                                                                                                                                                                                                                      130 ↵  ✹oculus 

> [email protected] test /Users/paris/repo/ua-parser-jparismorgan
> jshint src/ua-parser.js && mocha -R nyan test/test.js

 1979_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_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_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ ""  ""  

  1979 passing (8m)
Copy link
Owner

@faisalman faisalman left a comment

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]

Loading

@jparismorgan
Copy link
Contributor Author

@jparismorgan jparismorgan commented Oct 4, 2021

Great, thanks @faisalman, updated to use a single line regex. Confirmed the tests still pass:

~/repo/ua-parser-jparismorgan$ npm run test                                                                                                                                                                                                                             4 ↵  ✹oculus 

> [email protected] test /Users/paris/repo/us-parser-jparismorgan
> jshint src/ua-parser.js && mocha -R nyan test/test.js

 1972-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_,------,
 0   -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_|   /\_/\ 
 0   -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-^|__( ^ .^) 
     -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-  ""  "" 

  1972 passing (1m)

Loading

@jparismorgan jparismorgan requested a review from faisalman Oct 5, 2021
@faisalman faisalman merged commit 8fe448f into faisalman:master Oct 6, 2021
2 checks passed
Loading
allankronmark
Copy link

allankronmark commented on 343d584 Nov 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackpoll

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).

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants