Failed to execute "postMessage" in "DOMWindow": the specified source origin does not match the beginning of the recipient window ("null")

I have a game in heroku, now I'm trying to get it to work on Facebook canvas, but although it works in Firefox, in Chrome and IE not.

IE displays a warning with a button; when the button is clicked, the contents are displayed.

In chrome, I get this error:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://game.herokuapp.com') does not match the recipient window origin ('null'). 

What's wrong?

+23
javascript facebook heroku
Mar 05 '14 at 10:01
source share
6 answers

Make sure the destination window where you (or Facebook) post the message has completed the download. In most cases, I got this error when the iframe I sent messages to did not load.

+40
Mar 13 '14 at 13:22
source share

Another reason this could happen is to use an iframe with the sandbox attribute and allow-same-origin not set, for example:

 // page.html <iframe id="f" src="http://localhost:8000/iframe.html" sandbox="allow-scripts"></iframe> <script type="text/javascript"> var f = document.getElementById("f").contentWindow; // will throw exception f.postMessage("hello world!", 'http://localhost:8000'); </script> // iframe.html <script type="text/javascript"> window.addEventListener("message", function(event) { console.log(event); }, false); </script> 

I did not find a solution except:

  • add allow single-user version to the sandbox (did not want to do this)
  • use f.postMessage("hello world!", '*');
+21
Oct 12 '16 at 13:35
source share

To check if a frame is loaded, use the onload function. Or put your main function in the load: I recommend using the load when creating an iframe using js

  $('<iframe />', { src: url, id: 'receiver', frameborder: 1, load:function(){ //put your code here, so that those code can be make sure to be run after the frame loaded } }).appendTo('body'); 
+2
Sep 11 '14 at 2:03
source share

In my case, I did not add the http:// prefix. Potentially worth checking out.

+1
Jun 30 '17 at 7:31 on
source share

My problem was that from the very beginning I completely started the player, but instead of wrapping the div I used an iframe frame.

0
Nov 06 '18 at 11:59
source share

In my case, the SSL certificate was not valid for the iframe domain, so make sure that the iframe URL to which you are trying to send messages opens without any problems (in case you upload your iframe via https ).

0
Dec 21 '18 at 15:17
source share



All Articles