iframeyoutubepyscript

Why iframe for an embeded youtube clip does not work in pyscript?


I am making webpages in pyscript. When I add an iframe tag for an embeded youtube clip to an html that is hosted by pyscript.com, the html on a brower shows "www.youtube.com refused to connect."

Any advice how I can make the iframe work?

Here goes the content of my html file, which is uploaded on pyscript.com's server. I expected that my webpage shows a youtube clip that is ready to run, but instead, my webpage shows "www.youtube.com refused to connect."

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="https://pyscript.net/releases/2023.05.1/pyscript.css" />
    <script defer src="https://pyscript.net/releases/2023.05.1/pyscript.js"></script>
    <style>
    </style>
</head>
<body>
    <div>  
        <iframe width="560" height="315" src="https://www.youtube.com/embed/4xvC7Rlf2yw?si=mYYBe5-LoqkH-iHL" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
    </div>
</body>
</html>

Solution

  • The issue is caused by the site being a COEP environment, which requires iframes to have a COEP header.

    Adding credentialless attribute to the iframe should fix the issue. However, Firefox and Safari don't have support for this.

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#credentialless https://developer.chrome.com/blog/iframe-credentialless