brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: getEventListeners($0) lists which handlers are attached to an element

Javascript
~/tips/tip-devtools-geteventlisteners

getEventListeners($0)

Shows every event listener registered on the element you just inspected.

A click does something, but the markup has no onclick anywhere, so a script must have added the handler. The Console can tell me what is attached.

Select the element in the Elements panel, open the Console and run:

getEventListeners($0)

The Console utilities reference describes it as listing the event listeners registered on an object, and $0 is the element you inspected last. The result is an object with a key per event type, click or keydown for example. Expanding a key shows the listeners, and from there you can jump to the function and read what it does.

It takes any object, so the same call works on the whole document:

getEventListeners(document)

If you would rather not type, the Elements panel also has an Event Listeners pane for the selected element. I reach for the Console version when I want to compare two elements or see at a glance how many listeners one object has.

Like the other utilities, getEventListeners only exists in the DevTools Console, so your own page script cannot use it. It also reports the listeners of the exact object you pass. A handler that sits on a parent element, which is how event delegation works, will not appear on the child, so check the parents as well.

Further reading: Chrome DevTools: Console Utilities API reference, Chrome DevTools: breakpoints

More Javascript tips node --inspect-brk app.js obj?.prop const filePath = String.raw`C:\Development\profile\about.html`; const observer = new ResizeObserver((entries) => { URL.parse("not a url"); // null All Javascript tips (40) All topics

Link