Log javascript errors in Chrome?

醉酒当歌 提交于 2020-03-04 12:35:15

问题


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.

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.


回答1:


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

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.

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.

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.



来源:https://stackoverflow.com/questions/37401094/log-javascript-errors-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!