-1

Have an issue where an iframe with external source loads a page with errors thrown in console. What i'm looking for is a solution to grab these errors and determine what information to show based on them. There are multiple iframes loading within the page.

So, the code outside the iframe should track and collect the console info. How can I achieve this? Thanks!

Just an example I get this error in console: Refused to display 'http://[url]/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

I would like to catch this error and infrom user that the webpage could not load properly.

Adrian McCool
  • 143
  • 2
  • 12
  • 1
    You can't. The console is part of the browser, not Javascript. The only thing you could do is gracefully handle the errors in the script where they are generated. – Reinstate Monica Cellio Oct 19 '15 at 09:49
  • Is it really so? For example this post: http://stackoverflow.com/questions/11403107/capturing-javascript-console-log Or perhaps it is something else? I just do not understand how to do this. – Adrian McCool Oct 19 '15 at 09:56
  • Errors in the console are not there because there was a `console.log()` call - they are there because the browser is reporting them. That example that you gave is merely a method of overriding the existing `console.log()` function so that you can add extra functionality. That has nothing to do with Javascript throwing an error. – Reinstate Monica Cellio Oct 19 '15 at 09:58
  • If that is the case, I guess it will be difficult because I do not have any control over the content in each iframe. They are external webpages. – Adrian McCool Oct 19 '15 at 09:58
  • Added more information to my question. Please have a look. – Adrian McCool Oct 19 '15 at 10:02
  • Sorry, but I already answered you with the first 2 words I posted. More information won't change the fact. – Reinstate Monica Cellio Oct 19 '15 at 10:02
  • Okay thanks! Sorry, I thought this was possible. – Adrian McCool Oct 19 '15 at 10:05

1 Answers1

0

If you have an access to iframe's code, you can actually post messages to window.parent depending on errors and handle them on your side. Take a look at that at Mozilla's window.postMessage

philippsh
  • 788
  • 9
  • 17