You can also capture the trace as a string in case you want to log it elsewhere
var getTrace = function(top) {
var obj = {};
// in Chrome (or V8) this will return a string of the current call stack up to
// function top or this getTrace call itself
if ((typeof Error !== "undefined") && Error.captureStackTrace) {
Error.captureStackTrace(obj, top || getTrace);
}
return obj.stack;
};
This will return a string of the stack up to the call to getTrace itself (or up to another function if you pass in a parameter for top).
I tried putting this into a window.onError handler for this chrome extension I wrote that gives you a toolbar button to indicate javascript errors when the dev tools are shut
but you only get the stack trace of the engine calling the onError handler itself.. :(
But the routine can still be handy in your own code to get the trace as a string so you can pop it up in an message when the dev tools are closed.
--
T