在Chrome中记录JavaScript错误? [英] Log javascript errors in Chrome?

查看:80
本文介绍了在Chrome中记录JavaScript错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Chrome扩展程序,该扩展程序将记录Javascript控制台中显示的所有javascript错误,然后将其发送给我.

I'm trying to create a Chrome extension that will log all the javascript errors that show up in the Javascript console and then send that to me.

我一直在尝试chrome.debugger.onEvent.addListenerwindow.onerror,似乎没有任何运行.有人可以指出我正确的方向吗?

I've been trying the chrome.debugger.onEvent.addListener and the window.onerror and nothing seems to be running. Can someone point me in the right direction?

这些不是语法错误.它们是网络错误.该页面可能返回错误,我想记录该错误.

These are not syntax errors by the way. They are network errors. The page might return an error and I want to log that.

推荐答案

我发现评估网络性能在我的一项研究中,可能会对您有所帮助.

I found Evaluating network performance in one of my researches and it might help you.

它提到了网络"面板,该面板在DevTools打开时会自动记录所有网络活动.并且还使用了Resource Timing API,它是一种Javascript,可为每个加载的资源提供详细的网络时序数据,并且可用于任何网页,而不仅限于DevTools.

It mentioned about Network panel that automatically records all network activity while DevTools is open. And also uses the Resource Timing API, a Javascript that provides detailed networking timing data for each loaded resource and is available to any web page, not just DevTools.

尝试一下:打开当前页面上的JavaScript控制台,在提示符下输入以下内容,然后按Return键:

Try this: open the JavaScript console on the current page, enter the following at the prompt, and hit Return:

window.performance.getEntries()[0]

这将评估资源计时对象数组中的第一个元素,并在控制台中显示其属性.但是,请注意,默认情况下,导航到另一个页面或重新加载当前页面时,当前网络记录日志将被丢弃.

This evaluates the first element in the array of resource timing objects and displays its properties in the console. However, please note that by default, the current network record log is discarded when you navigate to another page, or reload the current page.

可以在文档中找到有关在这些情况下如何保存记录日志的更多信息.而且,除此之外,这篇SO帖子-如何使用Chrome的网络具有重定向功能的调试器也可能非常有用.

More information on how to preserve the recording log in these scenarios can be found in the documentation. And, in addition to that, this SO post - How to use chrome's network debugger with redirects can also be quite useful.

这篇关于在Chrome中记录JavaScript错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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