How to get result of console.trace() as string in javascript with chrome or firefox?

前端 未结 8 922
情话喂你
情话喂你 2020-12-02 12:31

console.trace() outputs its result on console.
I want to get the results as string and save them to a file.

I don\'t define names for functions and

8条回答
  •  醉酒成梦
    2020-12-02 13:23

    I was trying to get Stack Trace as string variable in JavaScript on NodeJS and this tutorial helped me. This will work in your scenario as well except stack trace is printed via Error Object than console.trace().

    Code to print stack trace:

    function add(x, y) {
        console.log(new Error().stack);
        return x+y;
    }
    

提交回复
热议问题