Refactoring DOM injection and adding better tracing of workers and XHR.

This cleans up a lot of the DOM injection code, making it much more readable and easier to follow (and removing the exceptions at startup). It is a little more conservative than before about hooking DOM on* events but should have less impact on performance.