Skip to content

fix(core): detect Oculus Browser instead of falling back to Chrome#3581

Open
Ashut0sh-mishra wants to merge 2 commits into
PostHog:mainfrom
Ashut0sh-mishra:fix/oculus-browser-detection
Open

fix(core): detect Oculus Browser instead of falling back to Chrome#3581
Ashut0sh-mishra wants to merge 2 commits into
PostHog:mainfrom
Ashut0sh-mishra:fix/oculus-browser-detection

Conversation

@Ashut0sh-mishra
Copy link
Copy Markdown

Problem

Events generated on Meta Quest headsets are reported with browser Chrome
instead of Oculus because the Oculus Browser user agent contains both
OculusBrowser and Chrome (and on newer firmware also SamsungBrowser),
and the existing detection order returns the first matching branch.

Closes #3574

Fix

  • Add OculusBrowser detection in detectBrowser before the
    SamsungBrowser / Chrome branches in packages/core/src/utils/user-agent-utils.ts.
  • Add a corresponding entry in versionRegexes so detectBrowserVersion
    returns the actual Oculus Browser version.
  • Constants follow the existing pre-uglifying string-concatenation style noted
    in the file header comment.

Tests

Added two new cases to packages/browser/src/__tests__/utils/user-agent-utils.test.ts:

  • Quest 2 UA (older format, with SamsungBrowser segment).
  • Quest 3-style UA (no SamsungBrowser segment).

Both assert expectedBrowser: 'Oculus Browser' and the correct
expectedVersion, exercising the same detectBrowser / detectBrowserVersion
suite the other browsers in this file go through.

Reference UA list: https://whatmyuseragent.com/browser/oc/oculus-browser

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>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

@Ashut0sh-mishra is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 12, 2026

Prompt To Fix All With AI
Fix 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

Comment thread packages/core/src/utils/user-agent-utils.ts Outdated
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>
@Ashut0sh-mishra
Copy link
Copy Markdown
Author

Thanks @greptile-apps! Inlined OCULUS directly into OCULUS_BROWSER -- you're right, it was only used once. Pushed.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 12, 2026

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 .greptile/rules.md and .greptile/config.json.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 12, 2026

Reviews (2): Last reviewed commit: "refactor(core): inline OCULUS constant i..." | Re-trigger Greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 12, 2026

Looks great — the inlined version is cleaner. The diff is in good shape:

  • OCULUS_BROWSER = 'Oculus Browser' is defined once and used in both detectBrowser and versionRegexes
  • The OculusBrowser string literal in the regex and includes() check is fine since it's a UA token, not a display name
  • Detection order is correct (before SamsungBrowser and Chrome)
  • Both test cases cover the right scenarios

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Oculus Browser is not properly being detected

1 participant