React-player: Failed to execute 'postMessage' on 'DOMWindow'

Created on 26 Oct 2018  路  12Comments  路  Source: cookpete/react-player

I last worked on my project about a month ago. At that time, I was able to get Youtube videos to load and play properly in react-player. After coming back, I've discovered that something seems to have changed and now the video won't load. I end with the following error:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://www.youtube.com') does not match the recipient window's origin ('http://localhost:8000').

I've looked up some StackOverflow questions about it and I've read that it's an error coming from the Youtube iFrame API when you make a request for a Youtube video over http instead of https. I put some logging in the react-player library and saw that the requests are supposedly being made over https, so I don't think that's the issue I'm having here.

Does anyone have any insight into this?

As an aside, I'm using Gatsby as my platform. Not sure if this really matters.

Most helpful comment

I'm getting the same warning although the videos work, did you resolve it?

All 12 comments

I'm getting the same warning although the videos work, did you resolve it?

@Tresky I'm getting this too. Any tips on a fix?

@NathanielHill @lloydh Hey guys. Whenever I was working on this, I discovered that I get the error mentioned above, but the player still functions properly. I never found a solution to stop this error from appearing.

I'm getting this error too.
@CookPete , Are you aware of this issue?
@Tresky , you closed the issue, even though it's relevant and hasn't been resolved. Do you mind reopening it?
image

I've reopened this issue because it seems to be a common problem experienced by many people. Hopefully, we can find a solution here.

Does the issue happen only on page load? Do all postMessage events function properly after the initial page load? It could be that events are trying to be posted to the hidden iframe before it gets loaded fully.

I'm aware of the issue, but afaik it's a problem with with the Youtube iFrame API based on whatever URL you are calling the API from, and it's not very consistent. This issue should remain closed unless there is a specific problem that ReactPlayer is causing.

There are plenty of mentions of the error elsewhere: https://www.google.com/search?q=youtube+iframe+Failed+to+execute+%27postMessage%27+on+%27DOMWindow%27%3A

However, ReactPlayer already tries to implement the solutions posted, eg adding the origin property to the playerVars. Also note this commit that pinned the API URL to https to try and prevent this issue.

If the error is still occurring (and not consistently) then I'm not sure what else can be done in this library.

This happens consistently on initial load for me. Is there another embedding technique? Having console errors lowers Lighthouse score which effects Google ranking.

Found something similar with Safari (on full screen) using vimeo. Getting a blocked a frame with origin error that I'm guessing is being thrown by postMessage.

It only happens in full screen though so I'm not entirely certain what to do.

is there a way to fix this? what is the current progress of the investigation for this?

There is no investigation happening, unless someone else wants to try and figure it out. My previous comment pretty much sums it up. If it's a problem with the Youtube and Vimeo players, this issue should be closed as there is nothing to fix in this library. However, I'm happy to leave it open for the time being for visibility, in case anyone wants to find out more.

@CookPete got it thanks.

So I found something interesting, upon using the yt-player library, well its the same implementation on this, but only on youtube, the player loads and its working, I think it loads upon re-rendering because I got this error.
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://www.youtube.com') does not match the recipient window's origin ('http://localhost:3000').

here is the code that i did on my project.
the videoId here is the videoId of the youtube and the on var is just for changing the tab.
btw what i do in here is that when you change the tab you just pause the current video.

https://gist.github.com/jaotors/c5fba976d04f72844b8402490fbcdd39

I hope this will help.

But if I'm embedding video like this there is no such error

<iframe 
   width="560" 
   height="315" 
   src="https://www.youtube.com/embed/D6RtJLpdUgI"
   frameborder="0" 
   allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" 
   allowfullscreen>
</iframe>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Thargarius picture Thargarius  路  3Comments

Betree picture Betree  路  4Comments

MDrooker picture MDrooker  路  6Comments

rpaschoal picture rpaschoal  路  5Comments

pwbrown picture pwbrown  路  8Comments