davidjbradshaw / iframe-resizer

Keep iFrames sized to their content.
https://iframe-resizer.com
Other
6.63k stars 978 forks source link

[Feature Request] Add onResizeError callback #1203

Closed raldred closed 5 months ago

raldred commented 5 months ago

It would be useful to know if there is an error resizing the frame.
This would allow us to handle this appropriately as without resizing the page maybe appear broken to the end user.

Could we add an onResizeError or similar callback?

davidjbradshaw commented 5 months ago

Not sure how to detect such an error. If you make a PR I’m happy to consider including it.

raldred commented 5 months ago

My initial thought would be to add a callback for the warning that gets logged out if the parents script doesn't hear back from the content. https://github.com/davidjbradshaw/iframe-resizer/blob/master/src/iframeResizer.js#L885

in that case maybe onTimeout?

davidjbradshaw commented 5 months ago

That's a warning rather than an error. You can get this message and everything still work. It's there to stop people raising tickets when they forget to add the JS into the iframe. But it can also be triggered by an iFrame just being slow to load.

If your worried about slow loading you can add so JS in your iFrame to send a message to the parent page when it is ready.

Maybe an onIframeReady event in the parent page would be more useful?

davidjbradshaw commented 5 months ago

Thinking a bit more we already have an onReady function, it's called onInit()