I’m trying to embed a video on my NextJS website by using <iframe
. The problem is it causes a lot of cookies issues in Chrome browser. Plus the performance dropped significantly.
<iframe
src="https://www.youtube.com/embed/r9jwGansp1E"
allowFullScreen
></iframe>
I also tried to use aspect-ratio plugin but I got the same issues and the page was rendered blank.
<div className="aspect-w-16 aspect-h-9">
<iframe
src="https://www.youtube.com/embed/r9jwGansp1E"
allowFullScreen
></iframe>
</div>
The question is am I doing it right? Or another way should be used to embed a video and avoid issues?
4
Answers
It would be better to use a library such as react-player to embed videos instead of using iframes, as iframes can sometimes result in cross-origin issues.
First, you won’t be able to solve this warning, because you cannot set the sameSite attribute as youtube is a third-party service.
If you have this issue in your local environment don’t worry, it should be gone when you deploy to a production server with HTTPS, it probably has something to do with the HTTP protocol.
You might want to look into YouTube iframe player API.
There is a really good sample on this page:
https://developers.google.com/youtube/iframe_api_reference
There is a resolution inside the very error.
Resolve this issue by updating the attributes of the cookie:
SameSite=none
andSecure
if the cookie should be sent in cross-site requests. This enables third-party useSameSite=Strict
orSameSite=Lax
if the cookie should not be sent in cross-site requests.Youtube.com has a ton of cookies. That is why you are recieving such an amount of errors.
Try to read the complete error next time 😉