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.

2 Answers 2

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
          }
        });
Sign up to request clarification or add additional context in comments.

2 Comments

if this works would be useful to give an example
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.
0

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

For more information read this

2 Comments

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. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.