Failed to execute postMessage on DOMWindow: The target origin provided does not match

AI-generated summary

Ingo_Karstein encountered a ‘postMessage’ error while embedding Discourse on a different domain (https://doc.test.dom) via JavaScript, with the error indicating a mismatch between target and recipient origins. He runs Discourse 2.0 via Docker behind an Nginx reverse proxy with SSL offloading on Ubuntu. Despite following the official embedding tutorial and configuring the embed host for doc.test.com, the issue persisted. He initially obscured URLs with spaces to comply with new-user posting limits Ingo_Karstein. Suggestions included verifying HTTPS usage and enabling force_https in Discourse settings vinothkannans, which Ingo tried without success Ingo_Karstein. The fix came when he ensured the discourseEmbedUrl in the embedded JavaScript exactly matched the referer URL of the embedding page Ingo_Karstein. The issue was resolved without further server-side configuration changes.

Hi all,

I try to solve this error since two days but with no success.

I use Discourse 2.0 (today) and used 1.9.x (yesterday).

I have a Ubuntu server with docker on it.

On the host I run nginx as reverse proxy with SSL offloading.

On the machine I host several docker images that run fine.

I installed Discource using “standalone.yml” with some modifications, e.g. port mapping from 80xx (host) to 80 (Discourse).

The Discourse URL from the Internet is something like this: https://discourse.example.com.

I try to embedd Discourse in a web site on a complete other domain, e.g. https://doc.test.dom

I added embedding settings to Discourse.

In the JavaScript console I get always this error:

Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https ://discourse.example.com’) does not match the recipient window’s origin (‘https ://doc.test.com’)

Any ideas?

I already tried to modify CORS settings in the Docker-Host-nginx.conf. No success.

Regards
Ingo

Did you follow this Howto? Embed Discourse comments on another website via Javascript

Make sure that you created an embeddable host in Discourse for doc.test.com and that the URLs in the JavaScript you embedded are correct and, in your case, use HTTPS.

It would be easier to help if we knew the actual URLs of your site. And did you change the error message you posted in any way? Because there is a whitespace in the URLs (https ://discourse.example.com).

I had to add the white spaces in the error message because the platform did reject my post as a new user is only allowed to have only 2 URLs in a new post. :wink:

I added the url “doc.test.com” in the embedding settings of Discourse.

Sorry… I forgot… Yes. I followed the tutorial.

You are using SSL and force_https is not yet enabled in your site settings. It can be the reason.

I changed the setting in Discourse administration. But I get the same result.

It works now! My last try was to edit the “discourseEmbedUrl” in JavaScript that need to be exact the referer URL / URL of the page where Discourse is embedded in.

Thank you all for your help!