0

I'm looking for something similar to what this guy was trying to do: Where to read console messages from background.js in a Chrome extension? but I can't find an answer on whether or not there is a way to listen and log console errors as they come in.

I don't need the content as the above commenter does, just to have some action performed if an error message appears on the console.

I'm trying to do something like this:

addEventListener("error", function(){ 
    ...some function...
}); 

where the function is triggered every time an error appears, but I can't seem to find anything that will do this in the Chrome developer documentation.

Anyone know of a solution?

stringgy
  • 85
  • 1
  • 1
  • 10
  • 1
    This is quiet an old SO related post but have you tried checking this [one](https://stackoverflow.com/questions/20323600/how-to-get-errors-stack-trace-in-chrome-extension-content-script)? – Mr.Rebot Nov 16 '18 at 06:14
  • 1
    Please clarify the question. Do you want to handle the extension background's console errors in itself? Why `addEventListener('error', ...)` or `window.onerror` is not suitable? – wrager Nov 16 '18 at 10:00
  • @wrager What I would really like is for anything that triggers a red message in the console to also trigger another action. I can play around with the two things you mentioned, but I was under the impression they would only handle js errors. I will explore them though. I'm just getting into Chrome extensions, maybe I wrote them off too quickly. Thanks. – stringgy Nov 16 '18 at 15:18
  • 1
    @stringgy It seems that there are no methods in the extensions API for catching the console messages. I can only advise you to additionally override `console.error` in order to catch error messages that has not been triggered by uncaught exceptions. – wrager Nov 16 '18 at 15:46

0 Answers0