ERROR - Unable to preventDefault inside passive event listener due to target being treated as passive

When zooming on an object using the mousewheel, this message appears.
It seems that there is no current solution for this a part from commenting the line of code, but we don’t know yet whether or not commenting results in any issue.
Furthermore it comes with every package we export from playcanvas, so it must concern everybody using your code.
Can you please provide us with some guidance on the matter? Or find a way to prevent this error from appearing on the console?

Is this below the correct way to solve this issue?
window.addEventListener(‘mousewheel’, function(e) {
e.preventDefault();
}, { passive: false });
I see that playcanvas.min.js uses this passive value, but it must have been wrongly set, otherwise it would work.

That’s correct for the browsers that support the new passive feature, but eventually it can lead to other kinds of errors in browsers that doesn’t.

For a proper workaround you would have to check for passive support first, and implement that only where it is required. Check the Safely detecting option support paragraph on the following MDN site for a nice solution on that:

Of course it would be lovely to have those scripts officially updated :slight_smile:

Thank you Leonidas!
Ok, then I assume it is better to way until the playcanvas library is officially updated rather than editing it now… given that (a part from the error message) we don’t see any issue (?).
Correct? What is your advice?

I can confirm that there is no issue in terms of functionality, apart from that error. Though that also means that we are at the mercy of Chrome, meaning that can change in the feature with any browser update.

I’d say if you would like to play it safe, implement that MDN workaround to get away with the error messages and make sure that this event listener functions as expected.

Ok we will try to implement that workaround directly in the playcanvas.min.js, if we spot where it should go. Fingers crossed.
Thank you Leonidas,

There is already an issue for this error in the engine repository:

If you add this to the engine you can also submit a pull request to get it added to the engine. PRs are most welcome.

Great, yes I will then submit a pull request, once added.
Thanks again for your help

1 Like

SOLUTION:
By editing the Mouse.js in the src/input of the engine-master in the following way, the error message disappears:

1 Like