I've extracted this question from this thread
I've been working on an oEmbed endpoint for consider.it that returns HTML that can be Oneboxed in a Discourse thread. Currently, the oEmbed html snippet is mostly just an iframe, along with a small javascript library injected into the containing window. This javascript library is capable of communicating with the iframe to dynamically adjust its height. This library is designed to play nicely with the containing window.
The specific code is e.g. :
<iframe id='considerit-embed-4186' src='https://dao.consider.it/embed/proposal/slockit1' width='700' frameborder='0' style='overflow:hidden' scrolling='no'></iframe>
<script src='https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.3/iframeResizer.min.js'></script>
<script type='application/javascript'>
var resize_interval=setInterval(function(){
if (typeof iFrameResize != 'undefined'){
iFrameResize({log:false, checkOrigin:false}, document.getElementById('considerit-embed-4186'))
clearInterval(resize_interval)
}
}, 40)
</script>
The javascript in the above code is unfortunately not consistently executing in a Discourse thread, and I'm at a loss as to why. I've observed the following bizarre but replicable behavior from Discourse:
- javascript DOES NOT run if I just load a thread containing a Oneboxed considerit link
- javascript DOES run if I have the post editor open with the link, but only for the Oneboxed link in the thread, not in the preview window.
This behavior is consistent when refreshing the page. I recorded this riveting 40 second video to demonstrate the behavior.
I can't tell if:
- Discourse intends to disable javascript for Onebox'd html oEmbeds (and the edit post behavior is a bug), or
- Discourse intends to enable javascript but there is a bug in Discourse or my own code that is preventing it from happening.
If (1), is there a recommended method for the provider to enable dynamically resizing Oneboxed content? Or is it impossible to dynamically resize Oneboxed content in Discourse?
If (2), is there a workaround or recommended course of action?
Thanks for your time,
Travis