serbanghita / Mobile-Detect

Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
http://mobiledetect.net
MIT License
10.52k stars 2.67k forks source link

Chrome, Firefox, Edge on iOS - wrong detection in desktop mode #857

Closed darapa1 closed 2 years ago

darapa1 commented 3 years ago

Issue description Using Chrome browser on iOS (iPhone and iPad) in Desktop Mode is detected as mobile.

User-Agent(s) regular working mobile mode (no issue): "Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1"

desktop mode (but still detected as mobile): "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87 Version/11.1.1 Safari/605.1.15"

Suggestions Looks like it is detected as mobile because of "isChrome" and "CriOS" string in user agent.

darapa1 commented 3 years ago

Could be fixed like this:

Original: 'Chrome' => '\bCrMo\b|CriOS|Android.Chrome/[.0-9] (Mobile)?', Fixed: 'Chrome' => '\bCrMo\b|CriOS.Mobile|Android.Chrome/[.0-9]* (Mobile)?',

As of Chome 84 the user agent has changed. "CriOS.*Mobile" will cover all mobile versions of Chrome on iOS.

What do you think?

darapa1 commented 3 years ago

Also Firefox and Edge is affected.

Following Changes would fix the issue (based on version 2.8.37)

Line 722: Original: |CriOS| Fixed: |CriOS.*Mobile|

Line 727: Original: \bEdgiOS\b| Fixed: EdgiOS.*Mobile|

Line 729: Original: |FxiOS Fixed: |FxiOS.*Mobile

On a iPhone you will be detected as mobile. If you change to destop mode you will be detected as a computer (and not longer as a mobile device) Based on documentation of Firefox, Chrome and Edge you will have "Mobile" for Phones inside the UA string.

Hope this helps!

davemacaulay commented 3 years ago

Thank you @darapa1, I manually applied your suggestions and they appear to work!

serbanghita commented 2 years ago

Thank you @darapa1 🙇