Skip to content Skip to sidebar Skip to footer

Passive Event Listeners

If I click the menu icon, chrome shows a warning in the console: [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event hand

Solution 1:

This is just a problem with Chrome. It happens even with only <select></select> and no event listeners. Chrome automatically logs whenever a scroll-blocking event occurs . Using Chrome's DevTools, I checked that there is no mousewheel listeners on the select box, and it still happens.

I suggest turning off 'Verbose' in the console.

Solution 2:

If you don't need to use .preventDefault() or do something, that has to occur, before the event ends, you should use the passive option in .addEventListener(), which doesn't block the event while your listener executes.

So your code would look like:

functionloadMenuBasedScript() {}
var getMenuDependentValues = "";
window.addEventListener("DOMContentLoaded", function() {
  document.getElementById("selectMenu").addEventListener('change', function() {
    menuSelected = this.value;
    loadMenuBasedScript(menuSelected, getMenuDependentValues);
  }, {
    passive: true
  });
}, false);
<body><div><selectid="selectMenu"><optionvalue="one">One</option><optionvalue="two">Two</option></select></div></body>

Post a Comment for "Passive Event Listeners"