1

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.

Dragonfly
  • 4,261
  • 7
  • 34
  • 60
  • You mean the log in background or content script? – CY_ May 23 '16 at 21:48
  • Can you show your code that is not working? – epascarello May 23 '16 at 21:49
  • I want to log the errors on occur page (Such as a failed ajax call. But I am using an extension to log this.) – Dragonfly May 23 '16 at 21:50
  • I am using ```window.onerror = function(msg, url, line)``` and tried injecting it onto the page with the extension: `"run_at" : "document_start"` with the JS. But it never goes into my function – Dragonfly May 23 '16 at 21:51
  • 1
    OK, so the console data in content script. As the answer in this post, there is no direct way to get console data: http://stackoverflow.com/questions/19846078/how-to-read-from-chromes-console-in-javascript – CY_ May 23 '16 at 21:52
  • How does applications such as Rollbar collect and log Javascript errors? I just want to report errors that users are facing without any 3rd party. – Dragonfly May 23 '16 at 21:55
  • Is there any chrome extension doing this similar things? If yes, may you can use crx viewer to check their code to find out how they did it – CY_ May 23 '16 at 21:57
  • sorry, I am not familiar with Rollbar. – CY_ May 23 '16 at 21:58
  • If understand Chrome extensions correctly, they have a different `window` from the browser window to keep extension data from leaking. – Jeremy J Starcher May 23 '16 at 22:27

1 Answers1

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.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22