Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

Why I can not show youtube url in laravel 8 app ?

I need to show youtube url in laravel 8 app. I found branch https://stackoverflow.com/questions/6666423/overcoming-display-forbidden-by-x-frame-options#answer-7469997

and using it I made in my blade file :

<?php
    header('X-Frame-Options: GOFORIT'); 
?>

...

<iframe width='640' height='480' src="{{ \Str::replace('watch?v=', 'embed/', old('youtube_url', $news->youtube_url)) }}"></iframe>

...

and using public video url

https://www.youtube.com/watch?v=xjqzftaWkmg

as a parameter I got error message : https://prnt.sc/ky8JRP6CI97T But clicking the “Watch on youtube” valid video on is opened. But why I can not see the video inside of my app page ? This app uses jquery 3.6. Any client/JS libraries ?

0 likes
5 replies
mstdmstd's avatar

@tisuchi @tisuchi when I copy video embedded code by SHARE button and paste it on my page in some case I got valid video box, but it some cases error box like https://prnt.sc/ky8JRP6CI97T

Looks like it depends on some options of the video... Which option is it? So my managers uploading video could set it...

1 like
tisuchi's avatar

@mstdmstd Can you show your code (where you paste your embedded code) and provide some sounding context?

1 like
mstdmstd's avatar

@tisuchi I got this https://www.youtube.com/watch?v=xjqzftaWkmg video and clicking on Share button I copypasted itto my form :

                    <div class="tab-pane container mt-3" id="youtubeTabPane">
                        <div class="col-12 form-group">
                            <label class="w-100 mb-0"><span class="d-block mb-1"> Youtube</span>
                                ::{{ old('youtube_url', $news->youtube_url) }}
                            </label>
                            <input
                                class="form-control"
                                name="youtube_url"
                                value="{{ old('youtube_url', $news->youtube_url) }}"
                            />


                            <iframe width="560" height="315" src="https://www.youtube.com/embed/xjqzftaWkmg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

                        </div>
                    </div>

In a console I see errors :

edit:298 Unrecognized feature: 'web-share'.
Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factor'.
DevTools failed to load source map: Could not load content for http://127.0.0.1:8000/js/perfect-scrollbar.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

If to clear

web-share

from the code I see errors in browser's console (Google Chrome Version 114.0.5735.90 on kubuntu 20)

Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factor'.
DevTools failed to load source map: Could not load content for http://127.0.0.1:8000/js/perfect-scrollbar.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

I copypasted code from small video lesson at link https://www.youtube.com/watch?v=ly36kn0ug4k and this copypasted code visible ok : https://prnt.sc/BpLP4efWSYlI

The code of these 2 iframes :

                            <iframe width="560" height="315" src="https://www.youtube.com/embed/xjqzftaWkmg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture;" allowfullscreen></iframe>


                            <iframe width="560" height="315" src="https://www.youtube.com/embed/ly36kn0ug4k" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

I suppose these are some youtube video props, which I could not find...

1 like
warpig's avatar

i have a component very similar, i receive the field value of the form in the blade and use the $videoURL to pass it to the iframe. i used this: html_entity_decode because it arrives like this: <p>hFLiMM7_OBM</p> then this:strip_tags to remove html tags. i am only using the video ID of a video, the string after "watch?v="

<?php
    $videoURL = \App\Models\TextWidget::getContent('youtube-sidebar');
    $videoURL = html_entity_decode($videoURL);
    $videoURL = strip_tags($videoURL);
?>
    <iframe 
        class="w-full aspect-video" 
        src="https://www.youtube.com/embed/<?php echo $videoURL?>"
        title="YouTube video player"
        frameborder="0"
        allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
        allowfullscreen>
    </iframe>

if you care about the php helpers, here you go: https://www.php.net/manual/en/function.strip-tags https://www.php.net/manual/en/function.html-entity-decode.php

Please or to participate in this conversation.