Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome "Emulate Touch Events" not working

I've enabled the "Emulate Touch Events" option in Chrome's Developer Tools. I set up a simple test program that alerts when I touch a <div>. The program works fine on my Galaxy Nexus, but when I click on the <div> in Chrome, even with the "Emulate Touch Events" option enabled, nothing happens. Any suggestions? Am I using this tool correctly?

Here's my code - nothing too fancy.

<!DOCTYPE html>
<html lang="en">
<head>      
    <style type="text/css">
        #main_div
        {
            position: absolute;
            width: 50px;
            height: 20px;
            background-color: red;
            top: 50%;
            left: 20px;             
        }           
    </style>
    <script type="text/javascript">
        function init()
        {
            main_div = document.getElementById("main_div");             
            main_div.ontouchstart = function() 
            {                    
                 alert("here");
            }                               
        }
    </script>
</head>
<body onload="init()">
    <div>
        <p id="x">hello</p>
        <p id="y"></p>
    </div>
    <div id="main_div">
        hello
    </div>
</body>
</html>
like image 700
Nathan Friend Avatar asked Jun 14 '12 00:06

Nathan Friend


4 Answers

What stumped me was that in addition to having the "Emulate touch events" checkbox checked, you also have to have the master "Enable" checkbox checked to enable overrides. Once both were checked, it worked fine.

enter image description here

like image 130
Mike Pollitt Avatar answered Oct 28 '22 05:10

Mike Pollitt


Touch events work in Chrome version 21 (not sure about previous versions) BUT you have to keep the Developer Tools window open in order for the touch events to occur. If you close the window you will go back to normal mouse events.

like image 32
Keith Avatar answered Oct 28 '22 05:10

Keith


As of Chrome 69, there's no Overrides pane in the settings, nor an Emulator drawer in the console. Instead, you can click the ... icon in the device view and then select "Add device type".

click "Add device type" to show the device type dropdown

While in Responsive mode, this will show you a little dropdown with the options "Mobile", "Mobile (no touch)", "Desktop", and "Desktop (no touch)". If you don't see it, expand the width of the device view pane. The default for Responsive mode is Mobile (which means touch events).

select which events to emulate in the device type dropdown

Note that when you select other pre-set devices, the device type will be set to Mobile and can't be changed. You can also select which device type you'd like to emulate when creating a custom device in Settings.

select device type when adding custom devices

like image 43
Galen Long Avatar answered Oct 28 '22 07:10

Galen Long


One important point that I've noticed - Checking "Emulate touch events" does not disable mouse events, it only adds a touch as well.

like image 22
Ledivin Avatar answered Oct 28 '22 06:10

Ledivin