Skip to content

Commit

Permalink
Merge pull request #9777 from kaliatech/fix-chrome-passive-evt-warning
Browse files Browse the repository at this point in the history
Fix passive event warning in chrome
  • Loading branch information
deltakosh authored Jan 12, 2021
2 parents d163b86 + 9ac4245 commit 6976462
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions dist/preview release/what's new.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
- Fix SSAO2 with PrePass sometimes causing colors brighter than they should be ([CraigFeldspar](https://github.com/CraigFeldspar))
- Fix PostProcess sharing between cameras/renderTargets, that would create/destroy a texture on every frame ([CraigFeldspar](https://github.com/CraigFeldspar))
- Fix for DualSense gamepads being incorrectly read as DualShock gamepads ([PolygonalSun](https://github.com/PolygonalSun))
- Fix for warning in chrome about passive wheel events ([#9777](https://github.com/BabylonJS/Babylon.js/pull/9777)) ([kaliatech](https://github.com/kaliatech))
- Fix crash when cloning material in `AssetContainer.instantiateModelsToScene` when mesh is an instanced mesh ([Popov72](https://github.com/Popov72))

## Breaking changes
Expand Down
23 changes: 22 additions & 1 deletion src/Inputs/scene.inputManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,28 @@ export class InputManager {
? "mousewheel" // Webkit and IE support at least "mousewheel"
: "DOMMouseScroll"; // let's assume that remaining browsers are older Firefox

elementToAttachTo.addEventListener(this._wheelEventName, <any>this._onPointerMove, false);
// Chrome reports warning in console if wheel listener doesn't set an explicit passive option.
// IE11 only supports captureEvent:boolean, not options:object, and it defaults to false.
// Feature detection technique copied from: https://github.com/github/eventlistener-polyfill (MIT license)
// ----------
var passiveSupported = false;
var noop = function () {};
try {
var options: object = {
passive: {
get: function () {
passiveSupported = true;
}
}
};
elementToAttachTo.addEventListener("test", noop, options);
elementToAttachTo.removeEventListener("test", noop, options);
} catch (e) {
/* */
}
// ----------

elementToAttachTo.addEventListener(this._wheelEventName, <any>this._onPointerMove, passiveSupported ? { passive: false } : false);
}

if (attachDown) {
Expand Down

0 comments on commit 6976462

Please sign in to comment.