Skip to content

Instantly share code, notes, and snippets.

@MeoMix
Created December 27, 2013 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MeoMix/37b4dbdbb3bd48f3c9e2 to your computer and use it in GitHub Desktop.
Save MeoMix/37b4dbdbb3bd48f3c9e2 to your computer and use it in GitHub Desktop.
YouTube IFrame Inject source
<!DOCTYPE html>
<html>
<head>
<title>
YouTube Test
</title>
<script type="text/javascript" src="background.js"></script>
</head>
<body>
<div id="YouTubeIFrameTarget"></div>
</body>
</html>
// When the YouTube API is ready, transform the <div> target into a
// YouTube IFrame. This will cause youTubeIFrameInject.cs to be injected into the iframe.
window.onYouTubePlayerAPIReady = function() {
new window.YT.Player('YouTubeIFrameTarget', {
width: 480,
height: 360,
events: {
'onReady': function () {
console.log("YouTube IFrameTarget is ready.");
},
'onError': function (error) {
console.error("An error was encountered.", error);
}
}
});
};
// Now load the YouTube IFrame API:
var youTubeIFrameAPIScript = document.createElement("script");
youTubeIFrameAPIScript.type = "text/javascript";
youTubeIFrameAPIScript.src = "https://www.youtube.com/iframe_api";
document.head.appendChild(youTubeIFrameAPIScript);
{
"name": "YouTube IFrame Inject",
"description": "Test code injection into a YouTube iframe",
"version": "1.0.0",
"permissions": [
"*://*.youtube.com/*",
"<all_urls>"
],
"background": {
"page": "background.html"
},
"content_scripts": [
{
"matches": ["*://*.youtube.com/embed/*"],
"all_frames": true,
"js": ["youTubeIFrameInject.js"]
}
],
"content_security_policy": "script-src 'self' 'unsafe-eval' https://www.youtube.com/iframe_api https://s.ytimg.com; object-src 'self'",
"manifest_version": 2
}
console.log("Test has loaded");
var requestId = window.requestAnimationFrame(function(){
console.log("requestAnimationFrame has completed successfully.");
});
console.log("Request Id:", requestId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment