Skip to content

Instantly share code, notes, and snippets.

@OutThisLife
Created July 27, 2018 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OutThisLife/e8c2b6911c86eed1ef7fbb3a13c15892 to your computer and use it in GitHub Desktop.
Save OutThisLife/e8c2b6911c86eed1ef7fbb3a13c15892 to your computer and use it in GitHub Desktop.
Get all event listeners from chrome.
// This is to list all events on the page:
[].slice.call(document.querySelectorAll('*'))
.map(el => ({ el, listeners: Object.entries(getEventListeners(el)) }))
.filter(el => el.listeners.length)
// Use with a mutationobserver to confirm that events are detaching:
const _getEventListeners = getEventListeners
const getAll = () => [].slice.call(document.querySelectorAll('*'))
.map(el => ({ el, listeners: Object.entries(_getEventListeners(el)) }))
.filter(el => el.listeners.length)
let tick
new MutationObserver(muts => {
const valid = muts.filter(({ type }) => type === 'childList')
if (valid.length && !tick) {
window.requestAnimationFrame(() => {
const list = getAll()
console.log('There are %d listeners', list.length, list)
window.requestAnimationFrame(() => (tick = false))
})
tick = true
}
}).observe(document.documentElement, { childList: true, subtree: true })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment