Skip to content

Commit

Permalink
Fix touch event detection for Chrome >= 70, see https://www.chromesta…
Browse files Browse the repository at this point in the history
  • Loading branch information
rejas committed Feb 28, 2019
1 parent 7da8cdb commit ab5febb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion feature-detects/touchevents.js
Expand Up @@ -35,8 +35,9 @@ This test will also return `true` for Firefox 4 Multitouch support.
*/
define(['Modernizr', 'prefixes', 'mq'], function(Modernizr, prefixes, mq) {
// Chrome (desktop) used to lie about its support on this, but that has since been rectified: https://bugs.chromium.org/p/chromium/issues/detail?id=36415
// Chrome also changed its behaviour since v70 and recommends the TouchEvent object for detection: https://www.chromestatus.com/feature/4764225348042752
Modernizr.addTest('touchevents', function() {
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
if (('ontouchstart' in window) || window.TouchEvent || window.DocumentTouch && document instanceof DocumentTouch) {
return true;
}

Expand Down

2 comments on commit ab5febb

@emiliodeg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always get true even if a untouchable screen.
W10
Chrome 72

@rejas
Copy link
Member Author

@rejas rejas commented on ab5febb Mar 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct behaviour, since the test doesnt detect if the device has a touchscreen but if the browser would support one. See the the codee snippet in the test:

  "warnings": [
    "Indicates if the browser supports the Touch Events spec, and does not necessarily reflect a touchscreen device"
  ],

Please sign in to comment.