Monkey Patching Event Listeners

There was an interesting question in my local slack javascript community for a way to capture the performance of different events that happen on a page.  One way that was suggested was to hook into the native event listeners on the DOM. So without further introduction, here’s one way to monkey patch event listeners on the DOM.

Here’s a runable codepen example:


See the Pen monkey patched event listeners by Michael Jasper (@mdjasper) on CodePen.