Skip to content

Instantly share code, notes, and snippets.

@thepeoplesbourgeois
Forked from tkafka/listAllEventListeners.js
Last active September 1, 2023 02:18
Show Gist options
  • Save thepeoplesbourgeois/66c2eeecc5b264efd41471ca5e354b1a to your computer and use it in GitHub Desktop.
Save thepeoplesbourgeois/66c2eeecc5b264efd41471ca5e354b1a to your computer and use it in GitHub Desktop.
List all event listeners in a document
function allEventListeners(){
const eventNames = Object.keys(window).filter(key => /^on/.test(key))
return [...document.querySelectorAll('*'), document].flatMap((node) => eventNames
.filter(event => node[event])
.map(event => {
return {
node,
event,
listener: (typeof node[event] === 'function') ? node[event].toString() : node[event]
}
})
)
}
console.table(allEventListeners())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment