如何监视浏览器中发出的所有自定义事件? [英] How can I monitor all custom events emitted in the browser?

查看:78
本文介绍了如何监视浏览器中发出的所有自定义事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监视在网络浏览器中触发的所有自定义事件。任何标准的浏览器都可以。

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.

推荐答案


我想监视在Web浏览器中触发的所有自定义事件。

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

我认为您不能。 DOM事件模型通过为特定事件类型设置侦听器来工作,因此,如果您不知道事件的类型,则无法监听。无法监听所有事件,例如没有 addEventListener('*',...)

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('*',...).

此外,您也不知道如何 custom 事件被调用。它们可能不会将事件调度到DOM中(例如,某些库实现了其自己的事件注册和处理系统),因此即使您可以跟踪事件的调度,也没有一般的方法来知道何时调用事件侦听器。

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.

这篇关于如何监视浏览器中发出的所有自定义事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆