How to get result of console.trace() as string in javascript with chrome or firefox?(如何使用chrome或firefox在javascript中将console.trace()的结果作为字符串?)
问题描述
console.trace()
在控制台上输出结果.
我想以字符串形式获取结果并将它们保存到文件中.
我没有为函数定义名称,也无法使用 callee.caller.name
获取它们的名称.
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 I also can not get their names with callee.caller.name
.
推荐答案
我不确定 firefox,但在 v8/chrome 中,您可以在 Error 构造函数上使用名为 captureStackTrace
的方法.(更多信息在这里)
I'm not sure about firefox, but in v8/chrome you can use a method on the Error constructor called captureStackTrace
. (More info here)
因此,获得它的一种 hacky 方法是:
So a hacky way to get it would be:
var getStackTrace = function() {
var obj = {};
Error.captureStackTrace(obj, getStackTrace);
return obj.stack;
};
console.log(getStackTrace());
通常,getStackTrace
在被捕获时会在堆栈上.那里的第二个参数将 getStackTrace
排除在堆栈跟踪中.
Normally, getStackTrace
would be on the stack when it's captured. The second argument there excludes getStackTrace
from being included in the stack trace.
这篇关于如何使用chrome或firefox在javascript中将console.trace()的结果作为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用chrome或firefox在javascript中将console.trace(


- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01