在Chrome扩展程序上可视化YouTube播放器iframe

时间:2016-11-28 13:30:00

标签: javascript google-chrome-extension youtube youtube-api

我是使用Youtube API和Chrome扩展程序的新手。为了更多地学习,我正在尝试创建一个简单的扩展程序,只需在扩展程序中播放YouTube视频/播放列表。 我制作了两个简单的htmljs文件,只创建了iframe和一个按钮。点击事件"发送"播放器中视频的 URL ,以此方式播放视频。如果我在浏览器中打开它,这非常有效,但是当尝试在扩展中打开它时,它不起作用(错误显示如下)。

我的html文件如下所示:(popup.html)

<html>
<head>
    <script type="text/javascript" src="buttons.js" charset="UTF-8"></script>
</head>

<body>
<div id="container">
    <iframe id="player" frameborder="0" allowfullscreen="1" title="YouTube video player" width="200"
            height="200"></iframe>
    <br>
    <button type="button" onclick="playVideo()">Play video</button>
</div>
</body>
</html>

我的简单js文件如下所示:(buttons.js)

function playVideo(){
    var player = document.getElementById("player");
    player.setAttribute("src", "https://www.youtube.com/embed/?listType=playlist&amp;list=XXXXXX&amp;enablejsapi=1&amp;widgetid=1");
}

每次尝试打开视频时都会出现此错误:

popup.html:11 Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

有没有人尝试过类似的东西?我只是想操纵扩展程序中的播放器,以便了解有关API和扩展程序的更多信息。发展。

0 个答案:

没有答案
相关问题