Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube "Blocked a frame with origin "http://www.youtube.com" from accessing a frame with origin" even if the same protocol is used

When embedding a Youtube playlist I am getting this error:

Blocked a frame with origin "http://www.youtube.com" from accessing a frame with origin "http://www.mydomain.com". Protocols, domains, and ports must match.

I am not mixing HTTP with HTTPS anywhere, so I don't know why I am getting this error in the first place.

I have noticed that recently the Youtube embedded playlist is not displaying the embed image of the first video and just displaying a black screen with a 'Play All' button, and I am wondering if this is being caused by the above error.

like image 732
jbx Avatar asked Jul 26 '13 08:07

jbx


People also ask

How do you fix blocked a frame with origin from accessing a cross origin frame?

The 'blocked a frame with origin "null" from accessing a cross-origin frame` error occurs because of `Cross-originn` request. To solve this error, you have a number of solutions like using a `local web server` or using the browser with `cross domain web security` disabled few solutions to number.

What does blocked a frame with origin mean?

Same-Origin Policy (SOP) restricts how a document or script loaded from one origin can interact with a resource from another origin.


1 Answers

Apparently it seems that the error given by chrome is a bug. In order to solve the black screen with 'Play All' button issue I used the Javascript API (instead of the iframe), like this:

<!DOCTYPE html>
<html>
  <body>
    <div id="player"></div>
    <script>
      var tag = document.createElement('script');
      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: '',
          events: {
            'onReady': onPlayerReady 
          }
        });
      }
      function onPlayerReady(event) {
        player.cuePlaylist({'listType':'playlist','list':'PLE2714DC8F2BA092D'});
      }
    </script>
  </body>
</html>

Thanks to @jlmcdonald for the answer, as indicated here: Youtube embedded playlist diplays playall button instead of the first video

like image 191
jbx Avatar answered Oct 07 '22 00:10

jbx