"Unable to preventDefault inside passive event listener due to target being treated as passive. " by chrome


#1

hello, on chrome browser i’m trying to track zoom distance.

I took the scene “Model viewer test scene”
https://playcanvas.com/editor/scene/784896

and basically use the same scripts but disabled the pan.

similar to the project i take the field ‘distance’ from OrbitCamera
same way OrbitMouseInput does using

var OverZoom = pc.createScript('overZoom');

// initialize code called once per entity
OverZoom.prototype.initialize = function() {
    this.orbitCamera = this.entity.script.orbitCamera;
    var fix;
};

// update code called every frame
OverZoom.prototype.update = function(dt) {
    fix = this.orbitCamera.distance;
    //console.log("current zoom is "+this.orbitCamera.distance);
};

the problem is that whenever i zoom, i do get zoom to contain the distance, but also recieve errors from chrome.

I looked on the web and the best solution was to replace scripts locally

not a solution that can work outside the development phase.
have you encountered it? is there a solution I can implement in the scene, script or project?

reproduction:

  1. create a project from https://playcanvas.com/project/629759/overview/model-viewer-test-scene this
  2. add to the camera a script called OverZoom and paste this code
var OverZoom = pc.createScript('overZoom');

// initialize code called once per entity
OverZoom.prototype.initialize = function() {
    this.orbitCamera = this.entity.script.orbitCamera;
    var fix;
};

// update code called every frame
OverZoom.prototype.update = function(dt) {
    fix = this.orbitCamera.distance;
    //console.log("current zoom is "+this.orbitCamera.distance);
};
  1. play the scene and zoom with wheel

#2

Well, I just went to mouse-input.js line 125 and deleted ‘event.event.preventDefault();’. Now that error is gone.


#3

thanks a lot

should I expect any consequences for not preventing default?


#4

I never had any consequences from that. Default behaviour of the mouse wheel would be scrolling up and down on a page, rather than zooming in and out. That never happened to me until now.


#5

This naturally doesn’t solve the issue when we DO want to prevent the scroll wheel from scrolling the page when PlayCanvas is hosted as an iFrame for example. I ran into this problem and have not found a solution yet. Preventing doesn’t work on Chrome