Print function log / trace for the whole program using firebug

Firebug has the ability to register calls for a specific function name. I am looking for an error that sometimes stops the page from rendering, but does not cause any errors or warnings. The error appears in about half the cases. So, how do I get a list of all function calls for the entire program or some kind of stack trace to execute the entire program?

+58
javascript firebug
Jan 12 '11 at 16:12
source share
4 answers

Firefox provides console.trace() , which is very convenient for printing a call stack. It is also available in Chrome and IE 11 .

Alternatively try something like this:

 function print_call_stack() { var stack = new Error().stack; console.log("PRINTING CALL STACK"); console.log( stack ); } 
+141
Apr 7 2018-12-12T00:
source share

When I need a stack trace, I do the following, maybe you can draw inspiration:

 function logStackTrace(levels) { var callstack = []; var isCallstackPopulated = false; try { i.dont.exist += 0; //doesn't exist- that the point } catch (e) { if (e.stack) { //Firefox / chrome var lines = e.stack.split('\n'); for (var i = 0, len = lines.length; i < len; i++) { callstack.push(lines[i]); } //Remove call to logStackTrace() callstack.shift(); isCallstackPopulated = true; } else if (window.opera && e.message) { //Opera var lines = e.message.split('\n'); for (var i = 0, len = lines.length; i < len; i++) { if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) { var entry = lines[i]; //Append next line also since it has the file info if (lines[i + 1]) { entry += " at " + lines[i + 1]; i++; } callstack.push(entry); } } //Remove call to logStackTrace() callstack.shift(); isCallstackPopulated = true; } } if (!isCallstackPopulated) { //IE and Safari var currentFunction = arguments.callee.caller; while (currentFunction) { var fn = currentFunction.toString(); var fname = fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")) || "anonymous"; callstack.push(fname); currentFunction = currentFunction.caller; } } if (levels) { console.log(callstack.slice(0, levels).join('\n')); } else { console.log(callstack.join('\n')); } }; 

Note moderator . The code in this answer also appears in this entry from Eric Wenderlin's blog . The author of this answer claims this as his own code, though, written before the blog post linked here. For good faith, I added a link to the message and this note.

+10
Jan 12 '11 at 17:07
source share

Try to execute one or more codes of one line or one function to determine where it stops working correctly. Or make some reasonable guesses and scattered registration operators through your code.

+2
Jan 12 '11 at 16:15
source share

I did this without firebug. Tested in both chrome and firefox:

 console.error("I'm debugging this code."); 

Once your program displays this on the console, you can click the small arrow on it to expand the call stack.

+2
Nov 16 '16 at 2:05
source share



All Articles