Questionable (seems like not always correct) mobile device detection


(Discourse.PRO) #1

I noticed that Discourse uses a questionable method for mobile device detection:

  def self.mobile_device?(user_agent)
    user_agent =~ /Mobile|webOS|Nexus 7/ && !(user_agent =~ /iPad/)
  end

Is it really correct?
Are all really used mobile devices comply with such regular expression?
For example, I see that Opera Mini User-Agent string does not contain «Mobile» word…
Why not use actual screen resolution as mobile device criterion?
For now, an absence of «Mobile» word in User-Agent breaks some screen elements.

For example:
meta.discourse.org look if I pass «Mobile» word in User-Agent:

and if I do not pass «Mobile» word in User-Agent:

I think the width of «320» is already enough to detect a browser as mobile.


(Régis Hanol) #2

How does the server know that your current viewport is 320 pixels wide?


(Discourse.PRO) #3

I think that adjusting forum header for browser screen resolution is not a server responsibility at all.


(Jeff Atwood) #4

Opera Mini is not a supported browser. You can check our FAQ to see what the supported browsers are. Generally the native browser on each platform.


(Kane York) #5

The server is responsible for deciding which stylesheet and which JS bundle you are getting, so yes.

The workaround is to go to the ≡ menu and click “Mobile View” (available whenever it is a touch device).