Skip to content

Instantly share code, notes, and snippets.

@mixu
Created June 7, 2013 00:23
Show Gist options
  • Save mixu/5726204 to your computer and use it in GitHub Desktop.
Save mixu/5726204 to your computer and use it in GitHub Desktop.
Stack trace experiment in Chrome
// this function can get the full stack trace, however, it's usefulness is
// somewhat limited by the fact that Chrome Dev tools can only display full
// urls that are passed as the first argument as a string. That means that
// every log line is preceded by a massively ugly URL block that works as
// a link but this is only mildly useful. There is no way to get the dev
// tools to linkify shorter URLs - if that were possible, then this
// might be a usable solution from a UI perspective
function getStack() {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function (err, stack) {
return stack;
};
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack.slice(4).filter(function(frame) {
return frame.getFileName() != undefined
});
}
var stack = getStack();
if(stack && stack[0]) {
args.push( stack[0].getFileName() +':' + stack[0].getLineNumber() );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment