Created
September 25, 2014 01:42
-
-
Save AdamTReineke/58c4696fb0bc07bd5247 to your computer and use it in GitHub Desktop.
Instrument addEventListener to provide async callstacks for Internet Explorer 11's developer tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Element.prototype._addEventListener = Element.prototype.addEventListener; | |
Element.prototype.addEventListener = function () { | |
var opID = Debug.msTraceAsyncOperationStarting("Element.prototype.addEventListener"); | |
var eventThis = this; | |
// Replace the user's function with a version wrapped with the async instrumentation calls | |
arguments[1] = (function (userFunc) { | |
return function instrumentAddEventListener() { | |
// We call that the async op completed instantly because the async op was the click | |
// event that started this call. | |
Debug.msTraceAsyncOperationCompleted(opID, Debug.MS_ASYNC_OP_STATUS_SUCCESS); | |
// Mark callback starting, fire the callback, mark callback completed. | |
Debug.msTraceAsyncCallbackStarting(opID); | |
userFunc.apply(eventThis, arguments); | |
Debug.msTraceAsyncCallbackCompleted(); | |
} | |
})(arguments[1]); | |
return Element.prototype._addEventListener.apply(this, arguments); | |
} |
Also works in for Visual Studio. (Currently testing a Cordova app, running as a WWA, on WP8.1.) It may be causing a few extra things to show up on the stack though...
The motivation is that in IE11, you only get async callstacks for XHR readyState == 4, setTimeout and setImmediate, IIRC. Also, YMMV. It is a definitely unsupported route to get async callstacks like this. VS seems to like this method a lot less than IE did.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: http://i.imgur.com/oQya3EZ.png