Skip to content

JavaScript crawler: Number of event listeners in common sites

Andres Riancho edited this page Mar 28, 2019 · 1 revision

Problem

After creating the JS crawler one of the doubts I had was: "How many event listeners are there in a page? How fast can we dispatch and handle all of them?"

Answer

To answer this question I created a test which browses to some common sites and gets all the event listeners. The test can be run using:

nosetests -s -v w3af/core/controllers/chrome/tests/test_count_event_listeners.py

The output is:

https://google.com/
{u'error': 1, u'load': 1, u'mousedown': 6, u'submit': 15}

https://www.google.com/search?q=w3af
{u'_custom': 1,
 u'blur': 1,
 u'change': 1,
 u'click': 1,
 u'dblclick': 1,
 u'error': 20,
 u'focus': 1,
 u'focusin': 1,
 u'focusout': 1,
 u'input': 1,
 u'keydown': 1,
 u'keypress': 1,
 u'keyup': 1,
 u'load': 20,
 u'mousedown': 72,
 u'mouseout': 2,
 u'mouseover': 2,
 u'mouseup': 1,
 u'paste': 1,
 u'speech': 1,
 u'submit': 17,
 u'touchcancel': 1,
 u'touchend': 1,
 u'touchstart': 1}

https://www.bing.com/
{u'click': 8, u'load': 73, u'submit': 4}

https://www.bing.com/search?q=w3af
{u'focus': 1, u'load': 234}

https://facebook.com/
{u'click': 9, u'submit': 43}

https://www.facebook.com/local/lists/350492278720904/
{u'click': 9}

https://cnn.com/
{}

https://edition.cnn.com/2019/03/27/uk/theresa-may-is-throwing-the-kitchen-sink-at-brexit-intl-gbr/index.html
{}

https://www.bbc.com/
{}

https://www.bbc.com/news/uk-politics-47729773
{u'click': 1}

https://www.wikipedia.org/
{u'blur': 1, u'input': 1, u'keydown': 1}

https://en.wikipedia.org/wiki/Cross-site_scripting
{u'beforeTabCollapse': 1,
 u'beforeTabExpand': 1,
 u'change': 1,
 u'click': 66,
 u'input': 1,
 u'keypress': 1,
 u'mouseout': 61,
 u'mouseover': 61,
 u'noresults': 1,
 u'paste': 1}

http://w3af.org/
{u'blur': 1, u'focus': 1}

http://w3af.org/take-a-tour
{u'blur': 2, u'focus': 2}

https://github.com/
{}

https://github.com/andresriancho/w3af
{}

https://web.whatsapp.com/
{}

Analysis

This is great. I was expecting ~1000s of event listeners per page and was thinking about hacks to speed-up the process... but it seems that the most common pages have less than 10 event listeners, and 'complex pages' have around 100.