[Solved] Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided does not match the recipient window’s origin (‘null’)

I have a game in heroku, now I’m trying to make it work in Facebook canvas, but, while it works in Firefox, in Chrome and IE doesn’t.

IE shows a warning with a button, when clicking the button, it shows the content.

In chrome, I get this error:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('') does not match the recipient window's origin ('null').

What’s wrong?

Enquirer: Sascuash


Solution #1:

Make sure the target window that you (or Facebook) is posting a message to, has completed loading. Most of the times I’ve gotten this error were when an iframe I was sending messages to had failed to load.

Respondent: Gustaff

Solution #2:

Another reason this could be happening is if you are using an iframe that has the sandbox attribute and allow-same-origin isn’t set e.g.:

// 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');

// iframe.html
<script type="text/javascript">
    window.addEventListener("message", function(event) {
    }, false);

I haven’t found a solution other than:

  • add allow-same-origin to the sandbox (didn’t want to do that)
  • use f.postMessage("hello world!", '*');
Respondent: Jamie McCrindle

Solution #3:

To check whether the frame have been loaded, use onload function. Or put your main function in load: I recommend to use load when creating the iframe by js

 $('<iframe />', {
   src: url,
   id:  'receiver',
   frameborder: 1,
     //put your code here, so that those code can be make sure to be run after the frame loaded
Respondent: twiii_florence

Solution #4:

In my case I didn’t add the http:// prefix. Potentially worth checking.

Respondent: nikk wong

Solution #5:

In my case SSL certificate was invalid for iframe domain, so make sure that iframe URL you’re trying to send messages to is opening w/o any issues (in case you load your iframe over https).

Respondent: Artyom Pranovich

Solution #6:

My issue was I was instatiating the player completely from start but I used an iframe instead of a wrapper div.

Respondent: Walter Kimaro

Solution #7:

In My Case, Im trying to pass messages from Salesforce Marketing Cloud Custom Activity(Domain 1) to Heroku(Domain 2) on load.

The Error Appeared in console, when I loaded my original html page from where message is being passed.

Issue I noticed after reading many blogs is that, the receiver page is not loaded yet.

I need to debug from my receiver page not from sender page.

Simple but glad if it helps anyone.

Respondent: Sharath Jallu

Solution #8:

This also reliably happens if you try to create a player without a videoId. Looks like that’s not supported.

Respondent: Mark

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy