使用 javascript 从浏览器的控制台获取数据 [英] Getting data from the browser's console using javascript

查看:115
本文介绍了使用 javascript 从浏览器的控制台获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道以前是否有人问过这个问题,但我希望能够从浏览器本身的错误控制台中获取数据(如果它支持),这将用于当用户发送错误报告它会提取与我网站上的页面相关的任何错误,例如代码中的拼写错误和其他以某种方式设法溜走的事情.另外,在这方面,有没有办法将错误从控制台传递到可用格式?如果这是不可能的,那么我可以告诉他们复制并粘贴来自网站本身的内容.

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.

我现在想到了这一点,因为我正在考虑如何使错误报告系统运行得更好,因为整个事情基本上都在浏览器中运行,而对于后端,我可以轻松地查看错误日志,但对于前端,即javascript 的一些东西并不那么容易.

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.

所以为了在一个小语句中完成所有这些,是否有一种简单的方法可以从错误控制台获取数据,并能够通过 javascript 将其发送到表单或类似的东西.

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.

推荐答案

可以使用 JS 中的 onerror 事件来获取错误的详细信息.例如,Hoptoad 执行此操作并将错误记录到他们的控制台,他们的代码重用了许多不错的 JS 脚本,包括很棒的 printStackTrace 函数......

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 从浏览器的控制台获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆