When writing How to remove event listener on Youtube player?, I tried to create a Stack Snippet but I could not add the YouTube API client, which was needed to display the issue.

The client is on https://www.youtube.com/iframe_api which does not include a .js extension and Stack Overflow adds an external library, which refuses to include the script. In lieu of a .js extension, it might work to test the mime-type of the URL.

There might be other sandbox issue around embedding a YouTube video on Stack Overflow but this was the first that stopped me.

  • 4
    Note that if you read this question carefully, it is on-topic. This is about embedding YouTube videos in Stack Snippets. As this question had four close votes, I cast the final close vote in order to expedite the reopening process. Commented Sep 13, 2018 at 1:55
  • 1
    Strange that people think this is not about the stack overflow website software. How could I had written it more clear? And what can I do now to make sure the right stack overflow developers see this? Commented Sep 13, 2018 at 2:09
  • 3
    We routinely get blatantly off-topic questions on this site, mostly to do with programming, which is why others may have more quickly voted to close this without paying much attention. I'd recommend editing this to make it more clear that it's on-topic. Commented Sep 13, 2018 at 2:12
  • Thanks to @ben-is-uǝq-backwards for the edit. Changing Code Snippet to Stack Snippet, should make it clear that this is about Stack Overflow's Stack Snippets. Commented Sep 13, 2018 at 14:35

1 Answer 1


After some testing, see below, I think this might be harder than it looks. It would still be great to have but will either require some help from YouTube peeps or a server proxy on StackOverflow.

function get() {
    return fetch('https://www.youtube.com/iframe_api', { mode: 'no-cors' })
        .then(function(response) {
            return response.headers
get().then(headers => {
    for (let h of headers.values()) {

Forget my idea about mime-type. Without CORS it will not work.

Failed to load https://www.youtube.com/iframe_api: No 'Access-Control-Allow-Origin' header is present on the requested resource.

  • We want response.headers.get('Content-Type') to equal application/javascript or similar. I think this can only be accomplished with a server-side request. Commented Sep 12, 2018 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .