3

I wanted to view custom events in the timeline of the web inspector of safari, or chrome's developer tools.

Has anyone had success creating events and having them displayed in the inspector? This would be extremely useful.

this doesn't show up in timeline:

var event = document.createEvent( 'CustomEvent' );
event.initCustomEvent('myEvent', true, false);
document.dispatchEvent( event );

this works, but it's a mouse event, which is not my intention:

var event = document.createEvent( 'MouseEvents' );
event.initEvent('click', true, false);
document.dispatchEvent( event );
pyramation
  • 1,483
  • 3
  • 19
  • 34
  • I also tried attaching events to objects, like MutationEvents, and console logged them (to prove they fired), and those also do not show up in the timeline. – pyramation Feb 22 '12 at 20:49

1 Answers1

4

You need to add a listener for your custom event.

document.addEventListener('myEvent', function() { console.log('myEvent'); });

var event = document.createEvent('CustomEvent');  
event.initEvent('myEvent', true, false);  
document.dispatchEvent(event);  

Source:

http://code.google.com/searchframe#OAMlx_jo-ck/src/third_party/WebKit/Source/WebCore/inspector/InspectorInstrumentation.cpp&exact_package=chromium&q=willDispatchEventOnWindowImpl&type=cs&l=337

Skomski
  • 4,590
  • 18
  • 30