0

Input: source html file, with JavaScript code and with possible errors in web content. Output: JavaScript code, that will print in alert the first error it can catch, after injecting into source html file.

I need to catch all errors that might pop up on web page by using JavaScript, here is non-exhaustive list of errors I need to register:

  • JavaScript errors
  • all image errors(image is not available, etc.)
  • iframes errors(source is not available, etc.)
  • other errors

On the first iteration it will be perfect to catch just JavaScript errors(can be done with window.onerror) and Image source errors.

Ievgen
  • 1,999
  • 2
  • 12
  • 24
  • What research have you done on this topic so far? – evolutionxbox May 23 '17 at 14:14
  • Possible duplicate of [Catch all javascript errors and send them to server](https://stackoverflow.com/questions/5328154/catch-all-javascript-errors-and-send-them-to-server) – Danziger May 23 '17 at 14:15
  • There are answers for all of those requirements in SO already: https://stackoverflow.com/questions/5328154/catch-all-javascript-errors-and-send-them-to-server, https://stackoverflow.com/questions/9815762/detect-when-an-image-fails-to-load-in-javascript, https://stackoverflow.com/questions/1353664/how-to-catch-javascript-errors-in-all-iframes-with-window-error... – Danziger May 23 '17 at 14:16
  • I have an input of html code, possibly with JS. From this in order to get output I need to inject JS, which triggers when one of mentioned errors pops up. – Ievgen May 23 '17 at 14:34

1 Answers1

0
window.onerror = function(msg) {
    alert('Error message: '+msg');
    return true;
}

For the list of error u should initialise an array and push all the error to that and finally check that array periodically. once the error shown in popup clear the data.

Hope it helps u.

Vinutha N
  • 156
  • 6