2

I am writing an HTML-only app and want to embed a YouTube IFRAME-based player. I used the demo code from https://developers.google.com/youtube/iframe_api_reference unfortunately, this does not seem to work out-of-the-box for HTML files loaded via the file:// protocol. I get the following error:

www-widgetapi.js:100

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').

I found Failed to execute 'postMessage' on 'DOMWindow': https://www.youtube.com !== http://localhost:9000 unfortunately it didn't help: whether I include it using their JS file via http or https doesn't matter.

Community
  • 1
  • 1
D.R.
  • 20,268
  • 21
  • 102
  • 205

2 Answers2

1

If you do not use your own IFRAME but instead let the YouTube API create the IFRAME -> no problems whatsoever. Don't know why though, so if anyone is able to elaborate I'd be interested.

Edit, some sample code, although it's a few years old:

let player = new YT.Player('gv-player-iframe', {
          height: playerHeight,
          width: playerWidth,
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange,
            'onError': onPlayerError
          }
        });
D.R.
  • 20,268
  • 21
  • 102
  • 205
  • if this works would be useful to give an example – bjw Jun 27 '22 at 11:27
  • Added my sample code from back in the days, however, the code is almost 6 years old and hasn't been used by myself for quite some time now, don't know if it still valid. All the best. – D.R. Jun 27 '22 at 12:53
0

The problem here is, you are running it through your file system. Instead try using local host.

For more information read this

Community
  • 1
  • 1
Techidiot
  • 1,921
  • 1
  • 15
  • 28
  • I've found that as well ... thing is, I don't want to run a local web server. The app should be HTML only. – D.R. Oct 01 '16 at 18:49
  • @D.R. You can have a HTML only app running on localhost. E.g. today's PWA's in development mode do just that most of the time. – Marcel Aug 14 '23 at 05:08