Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 on default image #45

Closed
Onyemobi opened this issue Dec 23, 2019 · 11 comments
Closed

404 on default image #45

Onyemobi opened this issue Dec 23, 2019 · 11 comments

Comments

@Onyemobi
Copy link

After loading the code in my CRM, I get a 404 on the default image ( https://i.ytimg.com/vi/null/hqdefault.jpg ) despite it showing up on my screen. Furthermore, the Youtube embed does not play.

@paulirish
Copy link
Owner

paulirish commented Dec 23, 2019 via email

@Onyemobi
Copy link
Author

87spd3KMs3U

@Onyemobi
Copy link
Author

Onyemobi commented Dec 23, 2019

<lite-youtube videoid="87spd3KMs3U">
    <div class="lty-playbtn"></div>
</lite-youtube>

@lborgman
Copy link

I use something like this. Not sure why anymore...

    async function getArturlImg(url) {
        if (!ytId) return undefined;
        async function checkImg(url) {
            const img = new Image();
            return new Promise((resolve, reject) => {
                img.onload = function () {
                    // console.warn(`Found ${url}`);
                    resolve(img);
                };
                img.onerror = function () {
                    // console.error(`Did not find ${url}`);
                    resolve();
                };
                img.src = url;
            });
        }
        let imgUrls = [
            `https://img.youtube.com/vi_webp/${ytId}/maxresdefault.webp`,
            `https://img.youtube.com/vi/${ytId}/maxresdefault.jpg`,
            `https://img.youtube.com/vi/${ytId}/default.jpg`,
        ];
        if (url) { imgUrls.unshift(url); }
        for (let i = 0, len = imgUrls.length; i < len; i++) {
            const url = imgUrls[i];
            const img = await checkImg(url);
            if (img) {
                if (img.naturalWidth === 120) {
                    if (i !== len - 1) {
                        // console.error(`Probably got YouTube fallback image, ${i}, ${len}: ${url}`);
                        continue;
                    }
                }
                return img;
            }

        }
    }

@Garbee
Copy link
Contributor

Garbee commented Feb 11, 2020

@Onyemobi Your default image URL has null where the ID should be. What CRM are you using and did you do any special integration module? Or is it just putting the direct HTML into a content block?

@rbardini
Copy link

rbardini commented Apr 3, 2020

This also happened to me when I loaded the script before using the element. Deferring the script solved the problem.

@pinkiebala
Copy link

I've run into the same situation when using lite-youtube with React.

According to spec:

The element must not gain any attributes or children, as this violates the expectations of
consumers who use the createElement or createElementNS methods.

In general, work should be deferred to connectedCallback as much as possible

Related issue: #44
Happy to see that it may be fixed in #28

@ghost
Copy link

ghost commented May 12, 2020

I have the same issue with a statically generated site using Nuxt.js
It works on the first-page load, but after navigating to a different page and returning to a page with a video - https://i.ytimg.com/vi/null/hqdefault.jpg and no longer can play it.

I used the same videoid from Readme.

@Garbee
Copy link
Contributor

Garbee commented May 12, 2020

@web2033 Do you have a minimal sample case that reproduces the issue?

@ghost
Copy link

ghost commented May 12, 2020

Do you have a minimal sample case that reproduces the issue?

@Garbee https://codesandbox.io/s/brave-pascal-cezu9

The first load works. Navigate to About Page and then back to Home and it doesn't work.

@paulirish
Copy link
Owner

The majority of the above cases were fixed in 0221be1 This is where you saw null in the image url.. it was because we used getAttribute before the element was available. (the true issue was #44 )

The @lborgman comment is more about using the best thumbnail available, which i've opened a dedicated issue for: #70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants