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

前端 未结 8 912
情话喂你
情话喂你 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:33

    you only need var stack = new Error().stack. this is simplified version of @sgouros answer.

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

    Probably will not work in every browser (works in Chrome).

提交回复
热议问题