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