在Chrome扩展程序中嵌入YouTube视频 [英] Embedding YouTube video in Chrome extension
问题描述
我想嵌入YouTube上托管的视频并在用户点击popup.html中的按钮时播放。
我按照此处列出的解决方案进行操作:
在Google Chrome浏览器扩展程序中显示YouTube视频
新标签会打开,但我看不到视频,我只看到一个灰色的矩形一个笑脸。
我想Google会以某种方式阻止视频。
是否可以在background.js打开的新标签上显示YouTube视频?
谢谢
编辑:
< div class =嵌入式响应嵌入式响应16by9>
< / div>
您正在使用协议相对URL: p>
src =// www.youtube.com/embed/XXXXXX?html5=1
同时,嵌入页面有一个URL,如
chrome-extension://yourextensionidhere/page.html
结果是 src
URL
chrome-extension://www.youtube.com/embed/XXXXXX?html5 = 1
这显然是无效的,并导致网络错误(在子帧中呈现为带有悲伤面孔的灰色页面)。
解决这个问题,将协议相对URL改为显式 https:// ...
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>
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://...
这篇关于在Chrome扩展程序中嵌入YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!