We need to access html body of the Iframe embedded video
Example :
We have a html
<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" width="420" height="345" frameborder="0" src="https://www.youtube.com/embed/KBk-ayp6yyU">
</iframe>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var iframe = document.getElementById("myFrame");
var elmnt = iframe.contentWindow;
console.log(elmnt);
}
</script>
</body>
</html>
We tried to retrieve iframe contents using above way but its throwing error saying
Uncaught DOMException: Blocked a frame with origin "https://localhost:8080" from accessing a cross-origin frame.
iframe.contentWindow.
Solution: Tried window.postMessage approach but not worked
followed below link but no luck
SecurityError: Blocked a frame with origin from accessing a cross-origin frame
Can anyone please help me , how to fetch iframe embedded video html contents?
We need iframe html body to modify the default video preview image.