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()的结果作为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Electron 渲染器进程中创建子窗口时如何修复How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器进程中创建子窗口
mainWindow.loadURL("https://localhost:3000/") 在 EmainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 应用程
Electron webContents executeJavaScript:无法在第二个 loaElectron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:无法在第二个 loadURL 上
如何在angular-cli的组件内使用电子浏览器窗口?how to use electron browser window inside components in angular-cli?(如何在angular-cli的组件内使用电子浏览器窗口?)
ElectronJS - 在 Windows 之间共享 redux 存储?ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之间共享 redux 存储?)
如何在电子应用程序中访问相机/网络摄像头?How to access camera/webcamera inside electron app?(如何在电子应用程序中访问相机/网络摄像头?)