-
-
Save thepeoplesbourgeois/66c2eeecc5b264efd41471ca5e354b1a to your computer and use it in GitHub Desktop.
List all event listeners in a document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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