Created
July 27, 2018 19:48
-
-
Save OutThisLife/e8c2b6911c86eed1ef7fbb3a13c15892 to your computer and use it in GitHub Desktop.
Get all event listeners from chrome.
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
// 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