Android mobile device detection is too strict


(Sam Saffron) #5

There should be a switch to mobile if we detect its a mobile device via JavaScript already in place.


(Felix Freiberger) #6

Wait, are you saying I shouldn’t see this button in Chrome on my laptop?

What is the criterion for mobile devices in the client-side JavaScript code?


(Jeff Atwood) #7

This already exists, not sure why we’re discussing it…


(Jeff Atwood) #8

Agreed but I know with 100% certainty that Nexus 7 used to be detected as mobile, and is not now.

user_agent =~ /Mobile|webOS|Nexus 7/ && !(user_agent =~ /iPad/)

To be clear, my goals are

  1. We should auto-detect mobile in Android Chrome and Android Firefox on Android (because Android tablets, LOL) and we can test this on our team Nexus 6p devices + the Nexus 7 devices…
  2. We should auto-detect mobile in Mobile Safari on 2012+ iOS 8,9 handheld devices

So I think only #1 is failing us at the moment…


(Eric Vantillard) #9

Not sure it is related but I have some problems displaying our forum on an IPhone 6 plus.

Using safari on my iPhone 6 plus

http://imgur.com/ZBFIcSt

and using Chrome on my iPhone 6 plus

http://imgur.com/zBeX0Be

my user agent using safari is

Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13C75 Safari/601

and my iOS version is 9.2 (13C75)

An other problem: When displaying the site using my phone in landscape mode The top navigation bar disappears.


(Jeff Atwood) #10

You must have some unusual setup in Safari, or unusual site configuration – I have never seen any Discourse site have trouble auto-selecting the mobile layout on iPhone… ever.


(Sam Saffron) #11

What is the user agent on your Nexus 7? Maybe it changed recently http://whatsmyuseragent.com/


(Charles Walter) #12

Would discourse ever consider leveraging a service like wurfl? or making this an option for admins in settings?

https://web.wurfl.io/#learnmore

“You can use the service free of charge, as long as your website is publicly available and does not require fees or paid subscription to access. Read the complete license here.”


(Jeff Atwood) #13

Unlikely, why take on a giant external dependency for something small like this?


(Jeff Atwood) #14

Also — anyone reading this who wants better android mobile device detection, please visit this site with the target device and paste in your results here, along with the specific make / model of your device as well as OS / browser version.

http://whatsmyuseragent.com/

Remember, we want to favor very popular Android devices running Android/Chrome, not necessarily all of them :wink:


(Jeff Atwood) #15

OK this Nexus 7 2013 with latest everything and beta Chrome is

Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MMB29Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.91 Safari/537.36


(Sam Saffron) #16

Very weird, the query string matches there … does this happen when you browse incognito?


(Luke S) #17

Nexus 10 2013-ish

Mozilla/5.0 (Linux; Android 5.1.1; Nexus 10 Build/LMY49G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.91 Safari/537.36

Note that on a device of this size, mobile version is the wrong choice for most users.

It seems to me that maybe viewport dimensions would be the way to go?


(Sam Saffron) #18

Trouble is, it would be a pretty complex change to shift the logic to the client.


(Luke S) #19

Then mobile version is structurally different, not just a set of CSS changes? That I could see being challenging…


(Sam Saffron) #20

If you ever click to view in desktop mode, it remembers forever. Do you get this issue when you browse incognito? Try going to hamburger and selecting mobile view.


(Eric Vantillard) #21

Thank you @sam. Seems to solve my problem :pray:


(Jeff Atwood) #22

All right here’s what we have had

user_agent =~ /Mobile|webOS|Nexus (5|6|7)/ && !(user_agent =~ /iPad/)

Here is what I am changing it to:

user_agent =~ /Mobile|Android|webOS/ && !(user_agent =~ /iPad|Nexus (9|10)/)

My iPhone 6s — matches Mobile

Mozilla/5.0 (iPhone; CPU iPhone OS 9_2_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13D15 Safari/601.1

My Nexus 7 — matches Android

Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MMB29Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.91 Safari/537.36

Nexus 10 — not-matches Nexus 10

Mozilla/5.0 (Linux; Android 5.1.1; Nexus 10 Build/LMY49G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.91 Safari/537.36

(this same regex is duplicated in two places, @sam said he’d clean it up)

Anyway, this broadens the matching substantially for Android. I am very fine with prioritizing phone and phablet layout for Android, as tablets are really a non-starter in the Android space. We feel it is the far lesser evil to have the (rare) Android full size tablet detected as mobile by mistake, than have one of the trillions of random Android phone models out there be detected as desktop by mistake.


Android mobile device detection is too broad
(Jay Pfaffman) #23

GALAXY S7 CHROME

A Analyze
Mozilla/5.0 (Linux; Android 6.0.1; SM-G930V Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.91 Mobile Safari/537.36


(Jeff Atwood) closed #24

This topic was automatically closed after 2 days. New replies are no longer allowed.