Using the YouTube Iframe API I get the following error in Safary 9.1, OS X Yosemite.
Unable to post message to http://www.youtube.com. Recipient has origin https://www.youtube.com
The page does work in other browsers (e.g. Firefox, Chrome etc). Also, it turns out that it's broken only on one specific machine. It does work on another machine running same OS and browser.
I have no idea where to start debugging this.
The iframe HTML code generated looks like this:
<iframe id="myVideo" frameborder="0" allowfullscreen="1" title="YouTube video player" width="200" height="200" src="http://www.youtube.com/embed/?html5=1&showinfo=0&autoplay=0&rel=0&controls=1&playsinline=1&enablejsapi=1&origin=http%3A%2F%2Fwww.example.com"></iframe>
The JavaScript code is this:
...
vid_frame = new YT.Player(id, {
height: '200',
width: '200',
videoId: id,
playerVars: {
html5: 1,
showinfo: showVideoInfo,
autoplay: 0,
rel: showRelatedVideos,
controls: showPlayerControls,
playsinline: 1
},
events: {
onReady: onPlayerReady
}
});
I feel like there is a browser setting that blocks the communication between the website and YouTube API but the error simply says that https://www.youtube.com
is trying to send something to http://www.youtube.com
(instead of https
).
I tried to manually change the http
into https
(in the iframe urls), but then I get warnings saying:
Untrusted origin: http://example.com
(because the main website is server over http
)
How to fix this?
I did see this related question: Unable to post message to http://www.youtube.com. Recipient has origin https://www.youtube.com
Where to start debugging this?