Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print current stack trace in JavaScript

How do I print a stack trace from JavaScript?

The answer How can I get a Javascript stack trace when I throw an exception? deals with throwing an exception, but I need to print stack traces to debug a memory leak.

Basically I've got the same question as Get current stack trace in Java but for JavaScript.

And How to print a stack trace in Node.js? is similar but it's Node.js and I want to know for JavaScript, more generally speaking, if it's different.

like image 792
Michael Osofsky Avatar asked Apr 05 '17 16:04

Michael Osofsky


People also ask

How do I print current stack trace?

Just use new Throwable(). printStackTrace() method and it will print complete stack trace from where a method is called, into the console.

How can I check my browser stack trace?

You can easily see the stack trace in JavaScript by adding the following into your code: console. trace(); And you'll get an outputted stack trace.

What is console trace in JavaScript?

Console trace() The trace() method displays a trace that show how the code ended up at a certain point.

Which console method can be used to print the stack trace to the point of its execution?

You can use console. trace() to get a quick and easy stack trace to better understand code execution flow.


1 Answers

This line of code gets a stack trace and prints it:

console.trace(); 

Source: https://developer.mozilla.org/en-US/docs/Web/API/Console/trace

like image 130
Michael Osofsky Avatar answered Sep 25 '22 21:09

Michael Osofsky