Embedding YouTube video in Chrome extension

泪湿孤枕 提交于 2019-12-25 07:35:26

问题


I would like to embed a video hosted on YouTube and play it when the user clicks on a button in popup.html.

I was following the solution listed here:

Showing a YouTube video in a Google Chrome extension

A new tab opens but I don't see the video, I only see a gray rectangle with a smiley inside.

I guess Google is blocking the video somehow. Is it possible to show YouTube video on a new tab opened by background.js?

Thanks

EDIT:

  <div class="embed-responsive embed-responsive-16by9">
      <iframe class="embed-responsive-item" src="//www.youtube.com/embed/XXXXXX?html5=1" frameborder="0" allowfullscreen></iframe>
  </div>   

回答1:


You are using a protocol-relative URL:

src="//www.youtube.com/embed/XXXXXX?html5=1"

At the same time, the embedding page has a URL like

chrome-extension://yourextensionidhere/page.html

This results in an src URL

chrome-extension://www.youtube.com/embed/XXXXXX?html5=1

which is obviously invalid and results in a network error (rendered in a subframe as a grey page with a sad face).

To resolve this, change the protocol-relative URL to explicit https://...



来源:https://stackoverflow.com/questions/37140814/embedding-youtube-video-in-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!