# Android mobile device detection is too strict

**URL:** https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943
**Category:** Bug
**Created:** [3월 12, 2016, 5:41오후 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943 "2016-03-12T17:41:03Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![charleswalter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/charleswalter/32/116433_2.png) [@charleswalter](https://meta.discourse.org/u/charleswalter)
#### Post date: [3월 12, 2016, 5:41오후 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/1 "2016-03-12T17:41:03Z")

</div>

Has there been any thought on reviewing how Discourse detects mobile devices? I was checking in my Chrome developer tools, and it doesn’t appear that LG devices are detected as mobile. I haven’t tested on a Samsung S6 or Motorola devices.

What is the current logic? Could it be improved?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 12, 2016, 9:58오후 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/2 "2016-03-12T21:58:07Z")

</div>

We should revisit this @neil since the nexus 7 is no longer default mobile as well.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 14, 2016, 6:10오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/3 "2016-03-14T06:10:47Z")

</div>

This is the algorithm we is crazy simple:

> <https://github.com/discourse/discourse/blob/0f7aaf5ab19f593416a0012f223e2f91e6cb0329/lib/mobile_detection.rb#L3>

compare to say, [http://detectmobilebrowsers.com/](http://detectmobilebrowsers.com/)

which recommends the crazy 🍌 💁

```ruby
def redirect_mobile(url = "http://detectmobilebrowser.com/mobile")
  redirect_to url if /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.match(request.user_agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.match(request.user_agent[0..3])
end

```

So it all just depends on how far we want to push this. Also it may make sense just to do the switch based on screen width in the client side, but it would change a big pile of things.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [3월 14, 2016, 7:00오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/4 "2016-03-14T07:00:54Z")

</div>

Maybe the simplest would be to have a “switch to mobile view” option for desktop view similar to the “switch to desktop view” that mobile view has?

IMHO it would still be good to have some detection in place, but for those that fall through the cracks I think there would be a better chance of them finding a “switch” link than it would be for them to realize they need to do a `?mobile_view=1`

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 14, 2016, 7:02오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/5 "2016-03-14T07:02:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [3월 14, 2016, 8:06오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/6 "2016-03-14T08:06:29Z")

</div>

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

![](https://global.discourse-cdn.com/meta/original/3X/b/a/ba348bfcdfe488dd49d52c272070309a507be4ed.png)

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 14, 2016, 9:36오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/7 "2016-03-14T09:36:29Z")

</div>

> [@Mittineague](#):
>
> Maybe the simplest would be to have a “switch to mobile view” option for desktop view similar to the “switch to desktop view” that mobile view has?

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 14, 2016, 9:40오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/8 "2016-03-14T09:40:31Z")

</div>

> [@sam](#):
>
> So it all just depends on how far we want to push this

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

```plaintext
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..

---

<div class="post-metadata">

### Author: ![evantill](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/evantill/32/116219_2.png) [@evantill](https://meta.discourse.org/u/evantill)
#### Post date: [3월 14, 2016, 9:45오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/9 "2016-03-14T09:45:16Z")

</div>

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

[![Imgur](https://global.discourse-cdn.com/meta/original/4X/a/7/b/a7be84a437ea7a6ca913b9962895fe7238844e3a.jpeg "imgur.com") ](https://imgur.com/ZBFIcSt)

and using Chrome on my iPhone 6 plus

[![Imgur](https://global.discourse-cdn.com/meta/original/4X/9/7/3/9730b610fbf966ab504c168f2aa4319fc7eaa3cd.jpeg "imgur.com") ](https://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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 14, 2016, 9:46오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/10 "2016-03-14T09:46:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 14, 2016, 11:07오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/11 "2016-03-14T11:07:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![charleswalter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/charleswalter/32/116433_2.png) [@charleswalter](https://meta.discourse.org/u/charleswalter)
#### Post date: [3월 14, 2016, 1:57오후 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/12 "2016-03-14T13:57:55Z")

</div>

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

> **[debug=true - WURFL.io](https://web.wurfl.io/#learnmore)**
>
> WURFL.js is JavaScript that detects device models of smartphones, tablets, smart TVs and game consoles accessing your website. Only WURFL.js Basic, Standard, and Pro services will detect iPhone and iPad models. The free WURFL.js Lite will only return...

“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.”

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 14, 2016, 4:59오후 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/13 "2016-03-14T16:59:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 15, 2016, 12:28오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/14 "2016-03-15T00:28:14Z")

</div>

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/](http://whatsmyuseragent.com/)

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 15, 2016, 2:55오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/15 "2016-03-15T02:55:15Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 15, 2016, 3:04오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/16 "2016-03-15T03:04:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Sailsman63](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Sailsman63](https://meta.discourse.org/u/Sailsman63)
#### Post date: [3월 15, 2016, 3:39오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/17 "2016-03-15T03:39:00Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 15, 2016, 3:41오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/18 "2016-03-15T03:41:06Z")

</div>

> [@Sailsman63](#):
>
> It seems to me that maybe viewport dimensions would be the way to go?

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

---

<div class="post-metadata">

### Author: ![Sailsman63](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Sailsman63](https://meta.discourse.org/u/Sailsman63)
#### Post date: [3월 15, 2016, 3:42오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/19 "2016-03-15T03:42:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [3월 15, 2016, 4:35오전 UTC](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943/20 "2016-03-15T04:35:39Z")

</div>

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.

[다음 페이지](https://meta.discourse.org/t/android-mobile-device-detection-is-too-strict/40943.md?page=2)
