Skip to content

fix wheel event handler Violation in Chromium by setting passive: true #7517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
simplify by removing handling for very old browsers
  • Loading branch information
emilykl committed Aug 11, 2025
commit 4054a618d998a9781832b69d7b7a081f48eb64a6
48 changes: 14 additions & 34 deletions src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,20 @@ var Events = {
internalEv.emit(event, data);
};

// Add a dummy event handler for 'wheel' event for Safari
// to enable mouse wheel zoom.
addDummyScrollEventListener(plotObj);
/*
* Add a dummy event handler for 'wheel' event for Safari
* to enable mouse wheel zoom.
* https://github.com/d3/d3/issues/3035
* https://github.com/plotly/plotly.js/issues/7452
*
* We set {passive: true} for better performance
* and to avoid a Violation warning in Chromium.
* https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
* https://github.com/plotly/plotly.js/issues/7516
*/
if(typeof plotObj.addEventListener === 'function') {
plotObj.addEventListener("wheel", () => {}, { passive: true });
}

return plotObj;
},
Expand Down Expand Up @@ -134,35 +145,4 @@ var Events = {

};

function addDummyScrollEventListener(plotObj) {
/*
* Add a dummy event handler for 'wheel' event for Safari
* to enable mouse wheel zoom.
* https://github.com/d3/d3/issues/3035
* https://github.com/plotly/plotly.js/issues/7452
*
* We set {passive: true} for better performance
* and to avoid a Violation warning in Chromium.
* https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
* https://github.com/plotly/plotly.js/issues/7516
*/

// Test whether the passive property is accessed (for compatibility with older browsers)
var supportsPassive = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true;
}
});
window.addEventListener("testPassive", null, opts);
window.removeEventListener("testPassive", null, opts);
} catch (e) {}

if(typeof plotObj.addEventListener === 'function') {
plotObj.addEventListener("wheel", () => {}, supportsPassive ? { passive: true } : false);
}

}

module.exports = Events;