Discourse embed fail (referer mixed up)

Hello,

I’m in the process of embedding Discourse in a Mediawiki instance, and I seem to have a strange issue with it.

When I link my wiki page to an existing discourse topic, everything works like a charm:

window.DiscourseEmbed = { discourseUrl: 'https://forum.dev.tripleperformance.fr/',|
                          topicId: 18};

But when I try to create the topic it fails:

window.DiscourseEmbed = { discourseUrl: 'https://forum.dev.tripleperformance.fr/',|
                          discourseEmbedUrl = 'https:' + mw.config.get('wgServer') + '/wiki/' + mw.config.get('wgPageName')};

The iframe is loaded a first time with:

<meta id="data-embedded" data-referer="https://wiki.dev.tripleperformance.fr/wiki/Sandbox">

Then, after 30 seconds (caused by the meta http-equiv="refresh" in the iframe), the iframe reloads with:

<meta id="data-embedded" data-referer="https://forum.dev.tripleperformance.fr/embed/comments?embed_url=https%3A%2F%2Fwiki.dev.tripleperformance.fr%2Fwiki%2FSandbox">`

At this point, there’s an error in the console:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://forum.dev.tripleperformance.fr') does not match the recipient window's origin ('https://wiki.dev.tripleperformance.fr').

That’s probably because the referer in the data-embedded attribute is now self and not the parent page (which might actually be expected since the initiator of the refresh is self).

Note: I’m on a development machine which is slow due to docker and everything. It’s quite possible that I’m in a race condition or something…?

For what it’s worth, I’ve tried to create a post in the forum with a link to a wiki page, and it managed to resolve it (the embed is properly displayed). I also tried to curl the URL from within the container with success. I don’t understand why the new topic is not created right away…