Last active
July 2, 2018 01:48
-
-
Save robwalch/7d2165353e2621bb7b21e29863b7ba5e to your computer and use it in GitHub Desktop.
Use Chrome's `getEventListeners` to list all even listeners added on the player container and child elements.
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(jwplayer) { | |
const container = jwplayer().getContainer(); | |
const elements = Array.prototype.slice.call(container.querySelectorAll('*')) | |
.filter(element => element.tagName !== 'path'); | |
elements.unshift(container); | |
const listeners = elements.reduce((accumulator, element) => { | |
const listenersObj = getEventListeners(element); | |
return accumulator.concat(Object.keys(listenersObj).reduce((accumulator2, name) => { | |
listenersObj[name].forEach(eventListener => { | |
eventListener.element = element; | |
accumulator2.push(eventListener); | |
}); | |
return accumulator2; | |
}, [])); | |
}, []); | |
const callbacks = Object.values(listeners.reduce((accumulator, listener) => { | |
const fn = listener.listener; | |
const key = `${listener.type}_${fn}`; | |
if (!accumulator[key]) { | |
accumulator[key] = { | |
count: 0, | |
type: listener.type, | |
name: fn.name, | |
fn | |
}; | |
} | |
accumulator[key].count++; | |
return accumulator; | |
}, {})) | |
.map(value => value) | |
.sort((a, b) => (b.count - a.count) || (parseInt((b.name + b.fn).substr(0, 20), 32) - parseInt((a.name + b.fn).substr(0, 20), 32))) | |
.map(listener => [ listener.count, listener.type, listener.name, listener.fn.toString().replace(/\s+/g, ' '), listener.fn ]); | |
return { | |
elements, | |
listeners, | |
callbacks | |
}; | |
}(window.jwplayer)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment