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

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

    Error.stack is what you need. It works in Chrome and Firefox. For example

    try { var a = {}; a.debug(); } catch(ex) {console.log(ex.stack)}
    

    will give in Chrome:

    TypeError: Object # has no method 'debug'
        at eval at  (unknown source)
        at eval (native)
        at Object._evaluateOn (unknown source)
        at Object._evaluateAndWrap (unknown source)
        at Object.evaluate (unknown source)
    
    
    

    and in Firefox:

    @http://www.google.com.ua/:87 _firebugInjectedEvaluate("with(_FirebugCommandLine){try { var a = {}; a.debug() } catch(ex) {console.log(ex.stack)}\n};")
    @http://www.google.com.ua/:87 _firebugEvalEvent([object Event])
    @http://www.google.com.ua/:67
    

    提交回复
    热议问题