Reputation: 36189
How do I get the trace of methods called in JS?
// file1.js
export const util = () => {
// get the complete trace
// from file2.js #start to file2.js #doSomething
}
// file2.js
import {util} from foo2.js
const doSomething = () => {
util();
}
const start = () => {
doSomething();
}
The only thing I can think of is to do new Error().stack
... Is there a better way?
Edit
What if I want to see the filenames too?
Upvotes: 2
Views: 60
Reputation: 496
Did you try console.trace()? That should do what you want.
https://developer.mozilla.org/en-US/docs/Web/API/Console/trace
Upvotes: 2