[solved] Error Embedding

AI-generated summary

A user, Michael321, encountered an “Error Embedding” issue when trying to embed comments from a Discourse topic into a static site. The JavaScript console error message indicated a mismatch between the target origin and the recipient window’s origin.

Michael321 was able to fix the issue by changing the discourseEmbedUrl to a full URL instead of a relative path.

codinghorror suggested adding a check for partial URLs to help diagnose similar issues in the future. eviltrout implemented this change, which will now warn users if a partial URL is detected.

Michael321 appreciated the feature and the quick fix, and also provided feedback on protocol-independent URLs.

Hi, similar to this post, I’m getting errors embedding comments in a static site: https://bigsmall.io/articles/action-brands-are-important-urgent-credible/

In the browser console, I it says “Loading Discussion”, then “Error Embedding” with this in the JavaScript console:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://community.bigsmall.io') does not match the recipient window's origin ('https://bigsmall.io').

The topics are created in Discourse - I see them in the “Let’s get this discussion started” page listing topics. From the dates, the topics may have been made from the RSS feed integration.

Any suggestions?

Bam! Fixed it. Make sure the discourseEmbedUrl is a full URL, not a relative path. E.g.:

              var url="https://dev.bigsmall.io/articles/action-brands-are-important-urgent-credible/"
              DiscourseEmbed = { discourseUrl: 'https://community.bigsmall.io/',
                                 discourseEmbedUrl: url };
              
              (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);
              })();

@eviltrout can we check for this somehow and warn if it is a partial URL?

Sure. It can only show in the Javascript console but it would have helped this person diagnose their issue:

https://github.com/discourse/discourse/commit/c40d8d37ddf75298ca837a60f42251e6f1fdf3d8

Yes! That would have saved us some time. This is a really cool feature BTW, it turns drive-by comments into a community which is cool.

I made a quick comment on the PR about protocol independent URLs. Cheers and thanks for an awesome project!

Mike