Archived topic
Does not use passive listeners to improve scrolling performance
4 replies · Started by Kenneth on July 1, 2021
Dear Team
I am facing this issue again. I had this problem before and then I added the below code using the snippets plugin. This code was provided in one of the support tickets here.
Example URL:https://www.noblehomeremedies.com/topical-treatments-for-cystic-acne-otc/
Kindly assist to overcome this issue.
Code added to the snippets plugin
---------------------------------
add_action( 'wp_footer', function () { ?>
<script>
(function() {
var supportsPassive = eventListenerOptionsSupported();
if (supportsPassive) {
var addEvent = EventTarget.prototype.addEventListener;
overwriteAddEvent(addEvent);
}
function overwriteAddEvent(superMethod) {
var defaultOptions = {
passive: true,
capture: false
};
EventTarget.prototype.addEventListener = function(type, listener, options) {
var usesListenerOptions = typeof options === 'object';
var useCapture = usesListenerOptions ? options.capture : options;
options = usesListenerOptions ? options : {};
options.passive = options.passive !== undefined ? options.passive : defaultOptions.passive;
options.capture = useCapture !== undefined ? useCapture : defaultOptions.capture;
superMethod.call(this, type, listener, options);
};
}
function eventListenerOptionsSupported() {
var supported = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supported = true;
}
});
window.addEventListener("test", null, opts);
} catch (e) {}
return supported;
}
})();
</script>
<?php } );
Hi there,
that issue is related to the comment-reply.js - which is a core WP Script.
Its a known bug that was reported here:
https://core.trac.wordpress.org/ticket/47510
And WP have chosen not to fix it, as in doing so it creates far greater issues.
The code you're using came from one of our users - we cannot support custom code.
There are several other methods posted in other forums like this method here:
https://dtlytics.com/2020/11/does-not-use-passive-listeners-solved/
But unfortunately we cannot assist with debugging problems with custom code.
Thank you for your reply. It is worth mentioning that...
GeneratePress is a complete and fully featured package that includes politeness, helpfulness, and respect.
Thank you so much.
Marking the issue as resolved by updating the check box.
You're welcome - and thank you for the kind feedback!