Firefox Developer Edition reporting support for touchstart event even when touch disabled

RESOLVED WORKSFORME

Status

RESOLVED WORKSFORME
4 years ago
4 months ago

People

(Reporter: bugs, Unassigned)

Tracking

35 Branch
x86
Mac OS X

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

954 bytes, text/html
Details
(Reporter)

Description

4 years ago
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/35.0
Build ID: 20150122214805

Steps to reproduce:

Javascript code that detects support for touchstart events always returns true, even when touch is disabled in the Responsive Design View.   Consider this code:

if ("ontouchstart" in document.documentElement) {
          alert("You are using a touch screen device");
} else {
          alert("You are using a normal screen device");
}

The browser always identifies as a touch screen device even when touch events are turned off.  So if you use this code to determine an event type (click vs touchstart), it will say it supports touchstart, but then won't fire any touch events!

This is using Firefox Developer Edition 37.0a2 on Mac OSX 10.9.5


Actual results:

It always returns true to support for touchstart


Expected results:

It should return false if touch is disabled
Could you please provide a html testcase either as attachment or as url ?
Flags: needinfo?(bugs)
(Reporter)

Comment 2

4 years ago
Here is a full HTML.  If you load this in the Firefox Developer Edition, the code detects that the browser supports touchstart, and so it adds a listener for touchstart instead of mousedown.  But if touch isn't enabled (in the Responsive Design View is the only place I know of to enable/disable it), then it never fires a mousedown event.   If you enable the touch, then it does fire mousedown.

But a lot of pages only build handlers for one or the other for the sake of simplicity and efficiency.  So the fact that the Developer Edition appears to be touch enabled even when it's disabled makes it so that detection code like this is useless, and makes pages that use it fail to work.

<!doctype html>
<html>
  <head>
    <title>Detect touch screen devices in Javascript</title>
    <meta charset="utf-8" />
    <style type="text/css">
      #canvas{background-color: #000;}
    </style>
    <script type="text/javascript">
      document.addEventListener("DOMContentLoaded", init, false);
      
      function init() {
        var canvas = document.getElementById("canvas");
        if ("ontouchstart" in document.documentElement) {
          canvas.addEventListener("touchstart", detect, false);
        } else {
          canvas.addEventListener("mousedown", detect, false);
        }
      }

      function detect() {
        if ("ontouchstart" in document.documentElement){
          alert("You are using a touch screen device");
        } else {
          alert("You are using a normal screen device");
        }
      }
    </script>
  </head>

  <body>
    <canvas id="canvas" width="150" height="150"></canvas>
  </body>
</html>
Flags: needinfo?(bugs)
(Reporter)

Comment 3

4 years ago
Another test that is often used is this one:

var clickEventType=((document.ontouchstart!==null)?'click':'touchstart');

//and this example using jQuery
$(".item").on(clickEventType, function(event){ doStuff(); });

//this fails in Firefox Developer Edition when touch is disabled too, because it detects that ontouchstart is supported, so it starts listening for it instead of click...
(Reporter)

Comment 4

4 years ago
Created attachment 8559204 [details]
touchtest.html

test case html
Component: Untriaged → DOM: Events
Product: Firefox → Core
(Reporter)

Comment 5

4 years ago
Also confirmed that this is NOT an issue on the Windows version of Firefox Developer Edition, only the Mac OSX version
I get "you are using a normal screen device" with Firefox38 on OSX10.9.5 and Windows7 and the given testcase from commwent#4
(Reporter)

Comment 7

4 years ago
Correct.  This is happening on a standard screen MacOSX 10.9.5 machine with no touch screen.
(Reporter)

Comment 8

4 years ago
Just confirming that this is still an issue as of Firefox Developer Edition 36.0a2.  Recent test was on OSX Yosemite 10.10.2, so it also appears to be independent of OSX version.

This bug makes the Developer Edition basically useless for developing responsive site designs that need to support both mouse and touch independently.
We should not be reporting touch support on OS X any more (for a while now, actually). Closing this as WFM, but please reopen if you are still running into this problem.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → WORKSFORME
Component: DOM: Events → Developer Tools: Responsive Design Mode
Product: Core → Firefox

Updated

4 months ago
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.