When window.onload is set by test code, phantomjs never exits.

I believe jQuery or some other library in my project was overwriting window.onload after the page was loading, so the logic to handle exiting phantom would never be called.

Changing this to use an event listener prevents it from being overridden.