Error Embedding for existing posts

Hello! We are getting an Error Embedding, the iframe says

Error Embedding
Referer: 
The referer was either not sent, or did not match any of the following hosts:

even though the domains are identical, and the console says:

Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin '' in a call to 'postMessage'.
    _embed-application-3723be59920e64ecda9d66b1e7c4c55378fb9dadfa7f422febd4f1b346c1aa05.js:6 Uncaught DOMException: Failed to execute 'postMessage' on 'Window': Invalid target origin '' in a call to 'postMessage'.
        at e (https://sjc1.discourse-cdn.com/business5/brotli_asset/embed-application-3723be59920e64ecda9d66b1e7c4c55378fb9dadfa7f422febd4f1b346c1aa05.js:1:42)
        at window.onload (https://sjc1.discourse-cdn.com/business5/brotli_asset/embed-application-3723be59920e64ecda9d66b1e7c4c55378fb9dadfa7f422febd4f1b346c1aa05.js:1:470)

We are using the ‘Alternate configuration’ so the solved topic doesn’t really help us.

(Alternate Configuration) Linking to existing topics

Some people prefer to not have Discourse create topics for them automatically on their forums. They’d like to create the topics themselves, then simply tell their embedding code what topic they want to associate with. You can do this by slightly changing your embedding code:

<div id='discourse-comments'></div>

<script type="text/javascript">
  DiscourseEmbed = { discourseUrl: 'http://discourse.example.com/',
                     topicId: 12345 };

  (function() {
    var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
    d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
  })();
</script>

The only difference here is we’ve replaced discourseEmbedUrl with the id of a topic from Discourse. If you do this, no topic will be created and the comments from that topic will automatically be displayed.

from Embedding Discourse Comments via Javascript

Any way we can debug this easily, where does it get the referrer and why could it be empty?
Is it a known/common issue and is there a way to hide the iframe or its contents when it errors?

Clicking through to the script where it errors it seems to not be able to find a referrer for a postMessage in the #data-embedded element.

You can look at the iframe that’s embedded in your page using the inspector and see if it has a meta tag with the correct referer. It should look something like: <meta id='data-embedded' data-referere="YOUR_SITE">

YOUR_SITE should be automatically populated by the iframe.

1 Like

<meta id="data-embedded" data-referer="">

It’s empty :scream:What does this mean?

It means for some reason the iframe you are embedding is not being supplied with a referrer. I’m not sure if something is stripping it, like a proxy or redirect, or if it’s a browser issue.

1 Like