问题描述
我不知道这是否曾被问过,但我想要做的就是从浏览器本身的错误控制台获取数据(如果它支持的话),这将是一个用户发送一个错误报告,它会拉出与我的网站上的页面相关的任何错误,例如代码中的打字错误和其他某些东西,无论如何设法滑倒。此外,在这方面有没有办法将错误从控制台传递到可用的格式?如果这是不可能的话,我可以告诉他们从网站本身复制粘贴。
我在想,关于如何使错误报告系统运行得更好,因为整个事情基本上都在浏览器中运行,对于后端,我可以轻松地查看错误日志,但是对于前端,即javascript的东西,它不会变得容易。 / p>
所以要在一个小的语句中完成所有这些,是否有一个简单的方法来从错误控制台获取数据,并能够通过javascript发送它
您可以在JS中使用onerror事件来获取错误的详细信息。 Hoptoad这样做,并将错误记录到他们的控制台,他们的代码重新使用了很多漂亮的JS脚本,包括一个很好的printStackTrace函数.....
你可以在这里看到他们如何做:
I don't know if this has been asked before, but what i'd like to be able to do is get data from the error console within the browser itself(if it supports it) this would be for when a user sends off a bug report it'd pull up any errors related to pages at my website for things such as typos in code and other things that somehow managed to slip by. Also, in that regard is there a way to pass the errors from the console to a useable format? If this isn't possible, then i could just tell them to copy and paste what came up from the site itself.
I thought of this right now as i was thinking about how to make the bug reporting system run better since the entire thing is basically ran within the browser and for the backend I can easily just look at error logs but for the frontend ie javascript bits of things it's not goign to be as easy.
So to finish wrap all of this up in one little statement, is there an easy way to get the data from the error console and be able to send it along via javascript ie to a form, or something similar.
You can use the onerror event in JS to get the details of the error. Hoptoad do this for example and log the errors to their console, Their code re-uses lots of nice JS scripts including a printStackTrace function that is great.....
You can see how they do it here:
http://hoptoadapp.com/javascripts/notifier.js
这篇关于使用javascript从浏览器的控制台获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!