Skip to content

Instantly share code, notes, and snippets.

@dejurin
Created April 13, 2025 09:12
Show Gist options
  • Save dejurin/c45c594f49eee701542943f4a25fc90f to your computer and use it in GitHub Desktop.
Save dejurin/c45c594f49eee701542943f4a25fc90f to your computer and use it in GitHub Desktop.
Monkey patch: Added non-passive event listener to a scroll-blocking 'wheel' event.
// This code patches addEventListener globally to force passive wheel events
if (typeof window !== 'undefined') {
const originalAddEventListener = window.EventTarget.prototype.addEventListener;
window.EventTarget.prototype.addEventListener = function(type, listener, options) {
if (type === 'wheel') {
// Transform options to object and force passive: true
if (options === undefined) {
options = { passive: true };
} else if (typeof options === 'boolean') {
options = { capture: options, passive: true };
} else if (typeof options === 'object') {
options.passive = true;
}
}
return originalAddEventListener.call(this, type, listener, options);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment