Created
April 13, 2025 09:12
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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