Javascript backtrace

How to get backtrace in javascript?

Ideal features:

  • the name of the login function or any meaningful identifier for anonymous functions,
  • a list of arguments at each level,
  • line numbers.

Can this be done in standard ECMAScript?

If not, can this be done in the general web browser dialog?

Thanks.

Edit -

Thanks for your suggestions.

My dialect does not support arguments.caller or arguments.callee .

I can do it:

 try { let x = null; x .foo (); } catch (e) { debug (dump (e.stack)); } 

Which gets me information as a string, which is understandable, but it would be very useful to go through e.stack . Does it have a standard shape?

Thanks again.

+9
source share
4 answers

Perhaps this may help you until it worked, but:

This link is no longer active: kallewoof.com/2006/03/15/precompiling-javascript-functions/

also look at this:

How to recognize caller function in JavaScript?

+4
source

In my debugging experience, I always use this

 (function () { console.log(new Error().stack); })(); 

As follows from the comments below, readers should prefer: console.log (new Error (). Stack);

+23
source

This lib: stacktrace-js works everywhere , not just with errors.

Example:

 StackTrace.get() .then(stack => { console.log(stack) }) .catch(err => { console.log(err) }); 
+1
source
0
source

All Articles