Existe esta respuesta: ¿puedo examinar y modificar mediante programación los controladores de eventos de Javascript en elementos html? pero no proporciona la solución de tiempo de ejecución
No hay ninguna API directa para esto, pero se puede acceder a ella de forma intrusiva.
Al anular HTMLElement.prototype.addEventListener , podemos capturar eventos agregados y almacenarlos en una matriz, por ejemplo.
const listeners = [] const originalAddEventListener = HTMLElement.prototype.addEventListener HTMLElement.prototype.addEventListener = function(type, listener, options) { listeners.push({ element: this, type, listener, options }) // call the original listener with current this and provided arguments return originalAddEventListener.call(this, type, listener, options) }Fragmento completo con ejemplo:
const listeners = [] const originalAddEventListener = HTMLElement.prototype.addEventListener HTMLElement.prototype.addEventListener = function(type, listener, options) { listeners.push({ element: this, type, listener, options }) return originalAddEventListener.call(this, type, listener, options) } document.querySelector('p').addEventListener('click', () => { console.log('clicked') }, false) document.querySelector('button').addEventListener('click', () => console.log(listeners)) p { width: 100px; height: 100px; background: red; color: white; } <button>list listeners</button> <p>click me</p>