Methods of removing the youtube iframe api console error - "blocked a frame with origin..." in chrome console

JavascriptYoutubeYoutube Api

Javascript Problem Overview


I'm using the youtube iframe api and get the following console error relating to the blocking of a frame with origin http://www.youtube.com. Was wondering if anyone can explain why this error is only appearing in the chrome console and if there are any ways to prevent this happening?

Error:

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

Javascript Solutions


Solution 1 - Javascript

I had a similar error where the JS error was:

> Blocked a frame with origin "https://www.youtube.com" from accessing a > frame with origin "http://www.yourdomain.com";. The frame requesting > access has a protocol of "https", the frame being accessed has a > protocol of "http". Protocol/Protocols must match, YouTube has CORS > (Cross Origin Resource Sharing) enabled to allow across domains.

Try getting rid of the https:// in your YouTube iframe tag?

You could also take a look at your closing iframe tags. Iframe tags are not singleton tags and must end with a </iframe> and not a />.

Solution 2 - Javascript

It seems that today, using the protocol-free "//youtube.com" URL that YouTube puts IN THEIR OWN EMBED CODE SNIPPET TOOL is throwing protocol matching errors. (sigh) This worked fine earlier this week.

If I add the https: to the embed URL it stops throwing errors and the iframe JS API works. It will continue to throw your "Blocked a frame with origin ..." error, but the JS API will function as expected.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionstylerView Question on Stackoverflow
Solution 1 - JavascriptWulf SolterView Answer on Stackoverflow
Solution 2 - JavascriptAndyView Answer on Stackoverflow