fix(core): detect Oculus Browser instead of falling back to Chrome#3581
Open
Ashut0sh-mishra wants to merge 2 commits into
Open
fix(core): detect Oculus Browser instead of falling back to Chrome#3581Ashut0sh-mishra wants to merge 2 commits into
Ashut0sh-mishra wants to merge 2 commits into
Conversation
Oculus Browser (Meta Quest) is Chromium-based, so its user agent includes OculusBrowser alongside Chrome (and on newer headsets SamsungBrowser). The current detection order returned Chrome (or Samsung Internet) for any Quest device. Add an OculusBrowser check before the SamsungBrowser/Chrome branches and a corresponding version regex, so events from Quest headsets are reported with Oculus Browser as the browser name. Added test cases covering both the older Quest 2 UA (with SamsungBrowser segment) and a Quest 3-style UA. Closes PostHog#3574 Co-authored-by: nik464 <nik464@users.noreply.github.com>
|
@Ashut0sh-mishra is attempting to deploy a commit to the PostHog Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/core/src/utils/user-agent-utils.ts:52-53
The `OCULUS` constant is only used once — to build `OCULUS_BROWSER`. The file header explains that intermediate constants exist for minification of *repeated* strings; `'Oculus'` doesn't appear anywhere else, so the intermediary adds a part with no benefit (simplicity rule #4). By contrast, the `'OculusBrowser'` UA token that appears twice in the file (detection check + version regex) was not factored out.
```suggestion
const OCULUS_BROWSER = 'Oculus Browser'
```
Reviews (1): Last reviewed commit: "fix(core): detect Oculus Browser instead..." | Re-trigger Greptile |
Addresses greptile review on PostHog#3581: `OCULUS` is only used once in the file, so the intermediate constant adds no minification benefit and violates the file's own simplicity convention (rule PostHog#4). Inline it. Co-authored-by: nik464 <nik464@users.noreply.github.com>
Author
|
Thanks @greptile-apps! Inlined OCULUS directly into OCULUS_BROWSER -- you're right, it was only used once. Pushed. |
Contributor
|
That's the clean approach — one less constant to track. The fix looks good overall. Thanks for the quick iteration! Tip: You can customize Greptile's behavior for this repo with |
Contributor
|
Reviews (2): Last reviewed commit: "refactor(core): inline OCULUS constant i..." | Re-trigger Greptile |
Contributor
|
Looks great — the inlined version is cleaner. The diff is in good shape:
LGTM. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Events generated on Meta Quest headsets are reported with browser
Chromeinstead of
Oculusbecause the Oculus Browser user agent contains bothOculusBrowserandChrome(and on newer firmware alsoSamsungBrowser),and the existing detection order returns the first matching branch.
Closes #3574
Fix
OculusBrowserdetection indetectBrowserbefore theSamsungBrowser/Chromebranches inpackages/core/src/utils/user-agent-utils.ts.versionRegexessodetectBrowserVersionreturns the actual Oculus Browser version.
in the file header comment.
Tests
Added two new cases to
packages/browser/src/__tests__/utils/user-agent-utils.test.ts:SamsungBrowsersegment).SamsungBrowsersegment).Both assert
expectedBrowser: 'Oculus Browser'and the correctexpectedVersion, exercising the samedetectBrowser/detectBrowserVersionsuite the other browsers in this file go through.
Reference UA list: https://whatmyuseragent.com/browser/oc/oculus-browser