0

I'm working on a local server, experimenting with the YouTube iframe API.

When loading iframes I get the error message "Failed to execute 'postMessage' on 'DOMWindow".

How do I eliminate this error?

bob
  • 753
  • 4
  • 15
  • 27

2 Answers2

0

I tried the Getting Started in the IFRAME API page and was able to run the sample without a hitch using the python -m SimpleHTTPServer 8080.

Your problem might be related to the way you're using iframe API. Check this SO post for more info.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
0

I think we could customize the sendMessage of the YT.Player

playerOptions.playerVars.origin = window.location.origin or your domain.
this.youtubePlayer = new YT.Player(element,playerOptions);
this.youtubePlayer.sendMessage = function (a) {
   a.id = this.id, a.channel = "widget", a = JSON.stringify(a);
   var url = new URL(this.h.src), origin = url.searchParams.get("origin");
   if (origin && this.h.contentWindow) {
       this.h.contentWindow.postMessage(a, origin)
   }
}

I used this function to resolve in my project. (Origin answer)

HoangHieu
  • 2,802
  • 3
  • 28
  • 44