Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3832

Cross-origin frame error while trying to get screenshot from iframe

$
0
0

I'm trying to get a screenshot from a youtube video with JavaScript. I am able to take it from youtube's website. But when i get the video in my own project with the iframe and try to get screenshot i am getting a cross-origin frame error. Is it possible to get screenshot from iframe?

(function(window, document) {    var iframe = document.querySelector('iframe');    var canvas = document.createElement('canvas');    var ctx = canvas.getContext('2d');    var iframeWindow = iframe.contentWindow;    var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;    var iframeImage = new Image();    iframeImage.onload = function() {        // Draw image on iframe        canvas.width = parseInt(iframe.offsetWidth);        canvas.height = parseInt(iframe.offsetHeight);        ctx.drawImage(iframeImage, 0, 0, canvas.width, canvas.height);        var base64ImageData = canvas.toDataURL('image/jpeg');        var filename = 'snap-'+ canvas.width +'x'+ canvas.height +'-'+ Date.now() +'.jpg';        var a = document.createElement('a');        a.download = filename;        a.href = base64ImageData;        var img = document.createElement('img');        img.src = base64ImageData;        img.alt = filename;        img.title = 'Click for save: '+ filename;        window.open().document.body.appendChild(a).appendChild(img);    };    // Upload iframe image    iframeImage.src = iframe.src;})(window, document);

Viewing all articles
Browse latest Browse all 3832

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>