最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I monitor all custom events emitted in the browser? - Stack Overflow

programmeradmin2浏览0评论

I'd like to monitor all custom events fired within a web browser. Any standard browser will do.

To be clear, I know you can attach event handlers to see when "usual" events are fired, but how can I reliably detect if an embedded object or jQuery script fires a custom event?

I could refactor the browser source code to hook the event loop, but that seems rather extreme.

I'd like to monitor all custom events fired within a web browser. Any standard browser will do.

To be clear, I know you can attach event handlers to see when "usual" events are fired, but how can I reliably detect if an embedded object or jQuery script fires a custom event?

I could refactor the browser source code to hook the event loop, but that seems rather extreme.

Share Improve this question edited May 6, 2019 at 17:48 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked May 12, 2011 at 21:14 Rob RaischRob Raisch 17.4k4 gold badges50 silver badges59 bronze badges 2
  • You could refactor the browser source code if you wanted to? Respect :) – Šime Vidas Commented May 13, 2011 at 0:50
  • Check out this question - it's about regular event types, but it might be useful... – Šime Vidas Commented May 13, 2011 at 0:52
Add a ment  | 

1 Answer 1

Reset to default 6

I'd like to monitor all custom events fired within a web browser.

I don't think you can. The DOM event model works by setting listeners for specific event types, so if you don't know the type of the event, you can't listen for it. There is no way to listen for all events, e.g. there is no addEventListener('*',...).

Also, you don't know how custom events are called. They may not dispatch an event into the DOM (e.g. some libraries implement their own event registration and handling systems) so there is no general way of knowing when event listeners are being called, even if you can track the dispatch of the event.

Some libraries also simulate event bubbling, but again, unless you know the type of event, you can't listen for it.

However, you could implement your own event management system and implement a function to listen for all events for which listeners are set or events dispatched using your system.

发布评论

评论列表(0)

  1. 暂无评论