web-js icon indicating copy to clipboard operation
web-js copied to clipboard

Add passive event listener patcher / forcer

Open alexander-schranz opened this issue 2 years ago • 0 comments

function forcePassiveEventListeners(eventNames) {
    const func = EventTarget.prototype.addEventListener;
    EventTarget.prototype.addEventListener = function(...args) {
        if (eventNames.includes(args[0])) {
            args[2] = passiveEvents ? {
                passive: false,
            } : false;
        }

        func.call(this, ...args);
    };
}
forcePassiveEventListeners(['scroll', 'touchmove', 'touchstart']);

alexander-schranz avatar Jan 18 '23 14:01 alexander-schranz