I am new at using the Youtube API and Chrome extensions. In order to learn a bit more, I am trying to create a simple extension that simply plays a YouTube video/playlist in the extension.
I've made two simple html
and js
files that just create the iframe and a button. The click event "sends" the URL of the video to the player and, that way, plays the video. This works very well if I open it in the browser but, when trying to open it in an extension, it doesn't work (the error is shown bellow).
My html
file looks like this: (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>
My simple js
file looks like this: (buttons.js)
function playVideo(){
var player = document.getElementById("player");
player.setAttribute("src", "https://www.youtube.com/embed/?listType=playlist&list=XXXXXX&enablejsapi=1&widgetid=1");
}
I get this error, every time I try to open the video:
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.
Has anyone tried something similar? I am just trying to manipulate the player inside the extension in order learn more about both the API and the extensions' development.