DEV Community

Danilo
Danilo

Posted on

Debug JS events with monitorEvents

It can be challenging sometimes to debug events, because of how many browsers and devices there are, so I wanted to share one underrated feature called monitorEvents that can track events on specific elements in the document.

Log all events firing on the body element

monitorEvents(document.body)
Enter fullscreen mode Exit fullscreen mode

Log all mouse events on the body

monitorEvents(document.body, 'mouse')
Enter fullscreen mode Exit fullscreen mode

Log all events on all input elements

monitorEvents(document.body.querySelectorAll('input'))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)