Consider marking event handler as 'passive' to make the page more responsive
For those receiving this warning for the first time, it is due to a bleeding edge feature called Passive Event Listeners that has been implemented in browsers fairly recently (summer 2016). From https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md:
Passive event listeners are a new feature in the DOM spec that enable developers to opt-in to better scroll performance by eliminating the need for scrolling to block on touch and wheel event listeners. Developers can annotate touch and wheel listeners with {passive: true} to indicate that they will never invoke preventDefault. This feature shipped in Chrome 51, Firefox 49 and landed in WebKit. For full official explanation read more here.
See also: What are passive event listeners?
You may have to wait for your .js library to implement support.
If you are handling events indirectly via a JavaScript library, you may be at the mercy of that particular library's support for the feature. As of December 2019, it does not look like any of the major libraries have implemented support. Some examples:
- jQuery.js - ongoing issue: https://github.com/jquery/jquery/issues/2871
- React.js - ongoing issue: https://github.com/facebook/react/issues/6436
React 17 discussion: https://github.com/facebook/react/issues/19651 - Hammer.js - closed due to no follow up: https://github.com/hammerjs/hammer.js/pull/987
- perfect-scrollbar - closed: https://github.com/noraesae/perfect-scrollbar/issues/560
- AngularJS - closed due to won't fix: https://github.com/angular/angular.js/issues/15901
The following library resolved the issue.
Simply add this code to your project.
<script type="text/javascript" src="https://unpkg.com/default-passive-events"></script>
If you need more information visit this library.
This hides the warning message:
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ) {
this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") });
}
};