Search code examples
javascripthtmliframecross-domain

Detect neterror of iframe (external site)


There was a problem that the external site that I had to bring as an iframe did not appear with a probability of about 5%. (If you click again, it will appear normally)

enter image description here

I want to retry if there is an error in the external site imported into the iframe. How can I detect that an error has occurred on an external site?

  • class list: neterror, sub-frame-error-details, sub-frame-error, main-frame-error) enter image description here

I tried to find the html tag or class name of the external site imported into the iframe but failed. enter image description here

And the onload function didn't work as expected either. This is because even if I call 'an external site with an error', 'my site' is judged as 'imported'.

Summary: How do I know on my own site that an error occurred on someone else's site that was imported into an iframe? My site judged that 'it was imported normally', so functions such as onerror did not work.

I asked the developer of an external site that imports into an iframe for help. However, he did not know the exact cause.


Differences from this question: SecurityError: Blocked a frame with origin from accessing a cross-origin frame

  • Normally, it is called normally.

  • The external site itself occasionally encounters network errors. (not my promblem)

  • As an analogy, my site shows the YouTube site as an iframe, which is exactly the same as the situation where YouTube's server is unstable and cannot show the video. The YouTube site itself is called normally.

enter image description here


Solution

  • You will need to look into your possibilities. I will tell you in advance that there are no easy solutions. But you have some means to try and solve this.

    First of all, look into postMessage and event listeners upon the message event. If the site you use happens to support your scenario and communicate whether the request has been successful or not, then it is quite possible that you will only need to addEventListener upon message events and see whatever message the source is sending you.

    Secondly, as you pointed out, you may send a message to the owner of the site, describe that your handling of that site is legitimate, convince them that it's their best interest to help you show their side inside your iframe and kindly ask them whether they already have some technical support for your case or whether they plan to implement such support.

    Finally, if all else fails, your server-side can send the requests to that site and display the content you receive as your page, belonging to the same domain. But this is undesirable and you should only consider using your page as a proxy if you do not violate the legal rights of the owner of the other site.