Skip to content

Conversation

@FaizanKamal7
Copy link

Summary

Fixes #50502

Modern Chrome on Android no longer includes the "Build/" string in its user-agent, causing it to be incorrectly identified as "Chrome (Linux)" instead of "Chrome (Android)" in the device list at /settings/user/security.

Problem

The current androidChrome regex pattern requires a Build/ string:

androidChrome: /Android.*(?:; (.*) Build\/).*Chrome\/(\d+)[0-9.]+/,

However, as of 2021, Chrome on Android has reduced its user-agent string and no longer includes the device model and build information.

Current user-agent format:

Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36

Solution

Updated the androidChrome regex pattern to:

androidChrome: /^Mozilla\/5\.0 \(Linux; Android[^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\) Chrome\/(\d+)[0-9.]+ (?:Mobile )?Safari\/[0-9.]+$/,

This pattern:

  • ✅ Matches modern Android Chrome (without Build string)
  • ✅ Matches Android Chrome on tablets (without "Mobile")
  • ✅ Still matches legacy Android Chrome (with Build string)
  • ✅ Correctly extracts Chrome version number
  • ✅ Does not incorrectly match desktop Chrome on Linux

Testing

Manual Regex Verification

Tested the new pattern using JavaScript console against the user-agent string reported in #50502:

const pattern = /^Mozilla\/5\.0 \(Linux; Android[^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\) Chrome\/(\d+)[0-9.]+ (?:Mobile )?Safari\/[0-9.]+$/;

// Modern Android Chrome (from issue #50502)
const ua1 = 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36';
const match1 = pattern.exec(ua1);
console.log('Modern Android Chrome - Match:', !!match1); // ✅ true
console.log('Version:', match1[1]); // ✅ "132"

// Android Chrome Tablet
const ua2 = 'Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
const match2 = pattern.exec(ua2);
console.log('Android Tablet - Match:', !!match2); // ✅ true
console.log('Version:', match2[1]); // ✅ "131"

// Legacy Android Chrome with Build
const ua3 = 'Mozilla/5.0 (Linux; Android 10; SM-G973F Build/QP1A) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.36';
const match3 = pattern.exec(ua3);
console.log('Legacy Android Chrome - Match:', !!match3); // ✅ true
console.log('Version:', match3[1]); // ✅ "130"

// Desktop Chrome on Linux (should NOT match)
const ua4 = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36';
const match4 = pattern.exec(ua4);
console.log('Desktop Linux Chrome - Match:', !!match4); // ✅ false (correct!)

Results:

  • ✅ Modern Android Chrome: correctly detected and version extracted
  • ✅ Android Chrome Tablet: correctly detected
  • ✅ Legacy Android Chrome: backwards compatible
  • ✅ Desktop Chrome on Linux: correctly NOT matched (prevents false positives)

Test Results Summary

  • Modern Android Chrome (primary issue): FIXED
  • Backwards compatibility with legacy user-agents: MAINTAINED
  • No false positives on desktop Chrome: VERIFIED

References

Checklist

  • Follows conventional commit format
  • Signed-off commit
  • Regex pattern tested against reported user-agent
  • Backwards compatibility verified
  • No false positives on non-Android Chrome

@FaizanKamal7 FaizanKamal7 requested review from a team as code owners November 14, 2025 23:05
@FaizanKamal7 FaizanKamal7 requested review from CarlSchwan, nfebe, provokateurin, skjnldsv and sorbaugh and removed request for a team November 14, 2025 23:05
@FaizanKamal7 FaizanKamal7 force-pushed the fix/android-chrome-detection branch from 43d1282 to b2554af Compare November 14, 2025 23:11
@github-actions
Copy link
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@FaizanKamal7 FaizanKamal7 force-pushed the fix/android-chrome-detection branch from f8cf84b to b89fc0f Compare December 3, 2025 12:32
@FaizanKamal7 FaizanKamal7 requested a review from a team as a code owner December 3, 2025 12:32
@FaizanKamal7 FaizanKamal7 force-pushed the fix/android-chrome-detection branch from b89fc0f to bae24eb Compare December 3, 2025 12:37
@FaizanKamal7 FaizanKamal7 reopened this Dec 3, 2025
@provokateurin
Copy link
Member

@FaizanKamal7 you don't need to update this branch unless there are conflicts. Also please rebase onto the master branch instead of merging it into this branch.

@FaizanKamal7 FaizanKamal7 force-pushed the fix/android-chrome-detection branch from 3de1e97 to 20f708f Compare December 4, 2025 15:32
@FaizanKamal7
Copy link
Author

FaizanKamal7 commented Dec 4, 2025

@FaizanKamal7 you don't need to update this branch unless there are conflicts. Also please rebase onto the master branch instead of merging it into this branch.

Noted @provokateurin. I will rebase it instead of updating this branch

@FaizanKamal7 FaizanKamal7 force-pushed the fix/android-chrome-detection branch from 20f708f to ed6a5f5 Compare December 7, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: In /settings/user/security Chrome on Android is detected as Chrome on Linux

3 participants