Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Attempt to spy on addEventListener
window.__numDomListeners = 0
function spyAddListener (proto) {
const addEventListener = proto.addEventListener
proto.addEventListener = function () {
window.__numDomListeners++
console.log('add', this, arguments)
return addEventListener.apply(this, arguments)
}
}
function spyRemoveListener (proto) {
const removeEventListener = proto.removeEventListener
proto.removeEventListener = function () {
window.__numDomListeners--
console.log('remove', this, arguments)
return removeEventListener.apply(this, arguments)
}
}
function spy (proto) {
spyAddListener(proto)
spyRemoveListener(proto)
}
spy(Element.prototype)
spy(document)
spy(window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment