15

Is there a way to distinguish a real mobile device from a device emulated by Google Chrome? Please note that Google Chrome can emulate Useragent, touchscreen, screen resolution and accelerometer. I need to know some features which cannot be emulated but can be detected by javascript.

Sergey Kravchenko
  • 957
  • 1
  • 8
  • 21

1 Answers1

6

It is possible to check for navigator.plugins.length. Mobile browsers have no plugins, so navigator.plugins.length is equal to 0; Desktop browsers ordinary have plugins, so we can distinguish browsers by length of plugins array.

Sergey Kravchenko
  • 957
  • 1
  • 8
  • 21
  • 9
    I'd say, that we can also use navigator.platform property. – Kamil Szymański Jan 22 '15 at 08:43
  • 4
    This no longer works. `navigator.plugins.length === 0` on Chrome when it's emulating iOS. – fregante Jun 18 '16 at 13:09
  • var isSmartDevice = /* mobile if android or iOS and not emulated in mac or win pc (for dev) \*/ (navigator.userAgent.match(/(android|ip(hone|ad|od))/i) && (!navigator.platform || !navigator.platform.match(/(win|mac)/i))) /* or if windows phone or blackberry (no dev in windows) */ || navigator.userAgent.match(/(windows phone|iemobile|wpdesktop|blackberry)/i); – ekerner Mar 08 '18 at 09:29
  • @KamilSzymański worked great for me. – Roee Apr 09 '18 at 10:51
  • 4
    The definitive way to determine this is to check for `navigator.maxTouchPoints > 1` Because Chrome emulated devices will always have only 1 touchpoint (ie. your mouse cursor), while actual (modern) mobile devices will always have more than 1, and devices without touch support will always have 0. You're welcome. – Ivan Apr 28 '20 at 08:16
  • @Ivan what would happen when someone using Chrome on laptop with touchscreen support? – blackbiron Nov 14 '20 at 16:52
  • 3
    @blackbiron I tested this: I have verified that `navigator.maxTouchPoints` is 10 on a touch screen computer when mobile emulation is *not* running, but it is 1 when mobile emulation is running. So that's good news. – Marc Durdin May 13 '21 at 04:14
  • thanks a lot @MarcDurdin – blackbiron May 18 '21 at 20:51