Search code examples
javascriptwebkit

How to handle touchpad force click in macos/chrome?


In youtube when you force click on a video while playing in a chrome browser, the video would be played at 2x.

Packages like Pressure.js cannot detect force click in chrome browser. How does youtube handle it?


Solution

  • YouTube could just be using a timer on the mousedown event. The timer just sees for how long you've held down on your mouse to validate if you're force clicking/holding.

    document.body.addEventListener('mousedown',function() { 
      setTimeout(function(){
        console.log("Holding!");
      }, 500);
    });