在 Firefox 中,我可以使用 exception.stack
来获取异常的堆栈跟踪。
其他浏览器是否也有类似的方式可以获取堆栈跟踪呢?
编辑:实际上,我希望能够自动保存堆栈跟踪(如果可能的话),而不是在运行时进行调试(即,我知道如何在调试器中获取堆栈跟踪)。
在 Firefox 中,我可以使用 exception.stack
来获取异常的堆栈跟踪。
其他浏览器是否也有类似的方式可以获取堆栈跟踪呢?
编辑:实际上,我希望能够自动保存堆栈跟踪(如果可能的话),而不是在运行时进行调试(即,我知道如何在调试器中获取堆栈跟踪)。
不太容易,至少不是那么简单。
在IE中,您可以使用MS Script Debugger(出于某种原因,它是Office组件)或Visual Studio调试浏览器进程,然后您可以在断点处查看堆栈。
window.onerror = function(message, url, lineNumber) { alert('message: ' + message + ' - url: ' + url + ' - ln: ' + lineNumber); return true; };
然后将其包装以打印出堆栈跟踪。try { // Some code that is causing the exception. } catch(e) { alert(new Error().stack); }
- Philip Murphy错误: ReferenceError: fdasmkl 未定义 at <anonymous>:6:7
而不是"错误: ReferenceError: fdasmkl 未定义 at eval (eval at <anonymous> (:6:1), <anonymous>:1:1) at <anonymous>:6:1"
- chitzuifunction foo() { fdasmkl } try { foo() } catch(e) { console.log(e.stack) }
- chitzui