Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to correctly imbed YouTube videos in HTML

I was trying to imbed a Youtube video in my website using iframe tag. However, many warnings appear on the console when using Chrome, such as:

Reading cookie in cross-site context will be blocked in future Chrome versions

I also read online that using iframe is discouraged due to security reasons.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To avoid breaking changes and security issues, I wonder if there is a better and safe way to imbed a YouTube video in my website apart from adding a video tag, as blocking external cookies is not possible as of my knowledge.

Here is my code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <iframe
      width="560"
      height="315"
      src="https://www.youtube.com/embed/dQw4w9WgXcQ?si=huEs0X_fKX95LMeh"
      title="YouTube video player"
      frameborder="0"
      allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
      allowfullscreen
    ></iframe>
  </body>
</html>

This is the complete warning log:

Reading cookie in cross-site context will be blocked in future Chrome versions

Cookies with the SameSite=None; Secure and not Partitioned attributes that operate in cross-site contexts are third-party cookies. In future Chrome versions, reading third-party cookies will be blocked. This behavior protects user data from cross-site tracking.

>Solution :

  • Go to the video on the YouTube web site
  • Click Share
  • Click Embed
  • Copy and paste the HTML you are offered into your own page.

Reference: https://support.google.com/youtube/answer/171780?hl=en

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading