Attention Onebox experts: Help requested resizing an iFrame embedded via oEmbed

Reviving an old thread: I’d like the same functionality, dynamically resized iframes. Since it seems allowing oembed providers to include script tags isn’t likely to happen (which I completely understand), a reasonable alternative would be for Discourse to implement a pretty simple hook.

Embed.ly provides this functionality by just sending a fairly simple postMessage, and on the host page, their library includes essentially this snippet:

window.addEventListener('message', function(e) {
  var data;
  try {
    data = JSON.parse(e.data);
  } catch (e) {
    return false;
  }

  if (data.context !== 'iframe.resize') {
    return false;
  }

  var iframe = document.querySelector('iframe[src="' + data.src + '"]');

  if (!iframe) {
    return false;
  }
 
  if (data.height) {
    iframe.height = data.height;
  }
});

Discourse could implement something compatible with this same message and a lot of things that work with embed.ly would just automatically work. From the implementor’s perspective, it’s as simple as sending this JSON whenever your iframe needs to be resized:

{
  "src": window.location.toString(),
  "context": "iframe.resize",
  "height": 999
}