Skip to content

fix: correct Android Mobile browserVersion regex casing (null $browser_version on Android) - #609

Open
sarmah-rup wants to merge 1 commit into
mixpanel:masterfrom
sarmah-rup:fix/android-browser-version-regex
Open

fix: correct Android Mobile browserVersion regex casing (null $browser_version on Android)#609
sarmah-rup wants to merge 1 commit into
mixpanel:masterfrom
sarmah-rup:fix/android-browser-version-regex

Conversation

@sarmah-rup

Copy link
Copy Markdown

What

The versionRegexs lookup in src/utils.js used a lowercase, unflagged pattern for the Android Mobile browser:

'Android Mobile': /android\s(\d+(\.\d+)?)/,

Real Android user agent strings spell the token with a capital Android (for example Mozilla/5.0 (Linux; U; Android 4.4.2; ...)), so this regex never matched. _.info.browserVersion() therefore returned null for these browsers. This changes the pattern to match the actual casing, consistent with every other place the same token is referenced:

'Android Mobile': /Android\s(\d+(\.\d+)?)/,

For reference, the sibling references already use the capitalized form: browser() (_.includes(user_agent, 'Android')), os() (/Android/.test(a)), and device() (/Android/.test(user_agent)).

Why (what I hit)

I was looking at my Android traffic in Mixpanel and noticed $browser_version coming through as null for a slice of users. The affected ones were non-Chrome Android browsers (older stock/WebView user agents classified as Android Mobile rather than Chrome). Those get their version parsed by the Android Mobile regex, which never matched because of the lowercase android, so every one recorded a null $browser_version. Chrome-on-Android was fine because it matches the separate Chrome/... pattern.

Test

Added a regression test in tests/unit/utils.js using a real Android 4.4.2 Samsung stock browser user agent (classified as Android Mobile, not Chrome), asserting _.info.browser(ua, '', false) equals Android Mobile and _.info.browserVersion(ua, '', false) equals 4.4. Before the fix the version assertion fails with expected null to equal 4.4. After the fix both pass. npm run unit-test -> 682 passing, npm run lint clean.

The `versionRegexs` table entry for `Android Mobile` used a lowercase
`/android\s.../` pattern with no `i` flag, so it never matched real user
agent strings, which contain a capital `Android`. As a result
`browserVersion` returned `null` for non-Chrome Android browsers, which
in turn recorded a null `$browser_version`.

Capitalize the pattern to `/Android\s.../` so it matches, consistent with
every sibling reference in `browser()`, `os()`, and `device()`. Adds a
regression test using a real Android 4.4.2 Samsung stock browser UA.
@sarmah-rup
sarmah-rup requested review from a team and rahul-mixpanel July 21, 2026 12:42
@rahul-mixpanel
rahul-mixpanel requested a review from jakewski July 21, 2026 17:10
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.

1 participant