Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I monitor all custom events emitted in the browser?

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.

like image 785
Rob Raisch Avatar asked May 12 '11 21:05

Rob Raisch


People also ask

How can I see Fired events in my browser?

Open Google Chrome and press F12 to open Dev Tools. Go to Event Listener Breakpoints, on the right: Click on the events and interact with the target element. If the event will fire, then you will get a breakpoint in the debugger.

How do you find out which Javascript Events fired?

Using Developer ToolsGo to the sources tab. Click on the Event Listener Breakpoints, on the right side. Then perform the activity that will trigger the event, i.e. click if the event that used is click, double click if it is dblclick event.

How do I debug a custom event in Chrome?

On the page, right-click the element you want to debug event listeners for, then click Inspect Element. In chromium-based browsers like MS Edge and Google Chrome, click the Event Listeners tab in Developer Tools. There, you'll see a list of all of the events being listened to on that element.


1 Answers

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.

like image 115
RobG Avatar answered Sep 21 '22 17:09

RobG