This is the error message that I get:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided
('https://www.youtube.com') does not match the recipient window's origin
('http://localhost:9000').
I've seen other similar problems where the target origin is http://www.youtube.com
and the recipient origin is https://www.youtube.com
, but none like mine where the target is https://www.youtube.com
and the origin is http://localhost:9000
.
I believe this is an issue with the target origin being https
. I suspect it is because your iFrame url is using http
instead of https
. Try changing the url of the file you are trying to embed to be https
.
For instance:
'//www.youtube.com/embed/' + id + '?showinfo=0&enablejsapi=1&origin=http://localhost:9000';
to be:
'https://www.youtube.com/embed/' + id + '?showinfo=0&enablejsapi=1&origin=http://localhost:9000';
That seems to have worked. Thanks! So the problem is
http
vs.https
? It doesn't matter that the domains differ (youtube vs. localhost)? And what exactly is target origin vs. recipient origin? How did doing what you said change the recipient origin (my url is still localhost:9000)?The error is a little misleading. It actually has nothing to do with you being on
localhost:9000
. The problem was actually in the way you were using the youtube-api. When you declare the api astag.src = "https://www.youtube.com/iframe_api";
in your code, you are telling youtube you want to use ssl. So, the change I suggested changed you to using ssl to request the videos. The error was just saying you were mixing ssl and non-ssl calls.I came across this issue when I tried to move the iframe around in the dom.
playerEl = document.querySelector('iframe#ytplayer'); anotherEl.appendChild(playerEl); // yt complains on subsequent api calls
what if I'm using javascript to load YouTube player?
changed to https:// for youtube and my domain is https:// still not solve my problem. Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘youtube.com’) does not match the recipient window’s origin (‘test.dev’).