JavaScript 查看stack trace


How can I get a JavaScript stack trace when I throw an exception?

Edit 2 (2017):

In all modern browsers you can simply call: console.trace(); (MDN Reference)

 

 

 

stacktrace.js

Generate, parse, and enhance JavaScript stack traces in all web browsers https://www.stacktracejs.com/

 

Debug and profile your JavaScript with a stack trace of function calls leading to an error (or any condition you specify).

stacktrace.js uses browsers' Error.stack mechanism to generate stack traces, parses them, enhances them with source maps and uses Promises to return an Array of StackFrames.

 

bower init

bower install stacktrace-js --save

 

或者

https://cdnjs.com/libraries/stacktrace.js  但是这是一个html页面

Resource blocked due to MIME type mismatch (X-Content-Type-Options: nosniff)

Check if the file path is correct and the file exists - in my case that was the issue - as I fixed it, the error disappeared

访问html页面,拿到https://cdnjs.cloudflare.com/ajax/libs/stacktrace.js/2.0.0/stacktrace.js

 

获取当前位置的堆栈信息

Get a stack trace from current location

var callback = function(stackframes) { var stringifiedStack = stackframes.map(function(sf) { return sf.toString(); }).join('\n'); console.log(stringifiedStack); }; var errback = function(err) { console.log(err.message); }; StackTrace.get().then(callback).catch(errback); //===> Promise(Array[StackFrame], Error) //===> callback([ // StackFrame({functionName: 'func1', args: [], fileName: 'file.js', lineNumber: 203, columnNumber: 9}), // StackFrame({functionName: 'func2', args: [], fileName: 'http://localhost:3000/file.min.js', lineNumber: 1, columnNumber: 3284}) //])

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM