Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to execute postMessage on DOMWindow #66

Open
spyesx opened this issue Feb 4, 2021 · 3 comments
Open

Failed to execute postMessage on DOMWindow #66

spyesx opened this issue Feb 4, 2021 · 3 comments

Comments

@spyesx
Copy link

spyesx commented Feb 4, 2021

Hi !

The following error keeps showing up constantly for a few days.

  • the website uses HTTPS
  • there is no autoplay
  • the origin is set manually just in case (ie: no window.location.origin)
www-widgetapi.js:629 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://youtube.com') does not match the recipient window's origin ('https://www.DOMAIN.TLD').

Tested on Chrome, Firefox and Safari.

The code is as follow:

      this._player = new YTPlayer('#player', {
        width: '100%',
        height: '100%',
        caption: false,
        controls: false,
        keyboard: false,
        fullscreen: true,
        annotations: false,
        modestBranding: true,
        related: false,
        host: 'https://www.youtube.com',
        showInfo: false,
        origin: 'https://www.DOMAIN.TLD'
      })
      this._player.load(this._YTVideoID)

Did I miss something?

@spyesx
Copy link
Author

spyesx commented Feb 4, 2021

Answer to myself and those who will face it.

Autoplay will not work. Play right after a load will not work.

      this._player = new YTPlayer('#player', {
        width: '100%',
        height: '100%',
        autoplay: true,
        caption: false,
        controls: false,
        keyboard: false,
        fullscreen: true,
        annotations: false,
        modestBranding: true,
        related: false,
        mute: 1,
        host: 'https://www.youtube-nocookie.com',
        showInfo: false,
        origin: 'https://www.soniawiederatherton.com'
      })
      this._player.mute()
      this._player.load(this._YTVideoID)
      this._player.play()

However, if you mute the sound before playing the video, you'll be ok. I still don't know why we get a postMessage error though oO.

Source: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

@cjlaserna
Copy link

The previous solutions for autoplay did not work for me but I eventually found a solution that did.

Instead of turning on autoplay on YTPlayer, specify it on load.
player.load("video", [true])

Source: Read the docs

@emahuni
Copy link

emahuni commented Jan 2, 2024

Was there ever a solution to this, I keep getting these error messages over and over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants