FitVids.js icon indicating copy to clipboard operation
FitVids.js copied to clipboard

Youtube iframe embed: Uncaught ReferenceError: yt is not defined

Open hammertimedk opened this issue 11 years ago • 14 comments

I'm seeing this js error pop up sporadically (Chrome) and it's triggered by the line

$this.wrap('<div class="fluid-width-video-wrapper"></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+"%");

I'm guessing this is when Fitvids wraps my iframe in some responsive magic, and the element then gets recreated on the page, or something like that? In any case, the only reference to this specific error I found online was: https://userscripts.org/topics/124302 - but that doesn't seem right as Fitvids doesn't seem to be referencing the yt variable/object in any way (neither does my code) - so I'm tempted to think this is a bug in Youtube's own js. Can't be sure though.

Here you can see it live (dev. site): http://skovstable.nes64.hammerti.me/

As mentioned, the error is sporadic and shows up rather randomly, so I'm also suspecting it has something to do with network/order of execution somewhere, which makes it even harder to pinpoint.

Anyhoo, here's hoping you've seen this before and know what this is all about :)

EDIT: Looked a bit closer and once Fitvids has done its thang, the iframe is loaded a second time (which makes sense). I'm thinking that sometimes, for some reason, the Youtube JS which the iframe contents depends on then sometimes doesn't get loaded/executed properly. Which may be a browser quirk, network problem at Youtube or simply crappy Youtube JS. Which basically means that Fitvids isn't responsible as such, except if there might be a way of wrapping the iframe with the Fitvids magic and not have the browser load the iframe twice?

hammertimedk avatar Dec 31 '13 12:12 hammertimedk

What browsers is this in? IE?— Sent from Mailbox for iPhone

On Tue, Dec 31, 2013 at 6:11 AM, hammertimedk [email protected] wrote:

I'm seeing this js error pop up sporadically and it's triggered by the line $this.wrap('

').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+"%"); I'm guessing this is when Fitvids wraps my iframe in some responsive magic, and the element then gets recreated on the page, or something like that? In any case, the only reference to this specific error I found online was: https://userscripts.org/topics/124302 - but that doesn't seem right as Fitvids doesn't seem to be referencing the yt variable/object in any way (neither does my code) - so I'm tempted to think this is a bug in Youtube's own js. Can't be sure though. Here you can see it live (dev. site): http://skovstable.nes64.hammerti.me/ As mentioned, the error is sporadic and shows up rather randomly, so I'm also suspecting it has something to do with network/order of execution somewhere, which makes it even harder to pinpoint.

Anyhoo, here's hoping you've seen this before and know what this is all about :)

Reply to this email directly or view it on GitHub: https://github.com/davatron5000/FitVids.js/issues/151

davatron5000 avatar Dec 31 '13 12:12 davatron5000

Sry - Chrome - Ive edited the issue with a bit more info :-) On 31 Dec 2013 13:31, "Dave Rupert" [email protected] wrote:

What browsers is this in? IE?— Sent from Mailbox for iPhone

On Tue, Dec 31, 2013 at 6:11 AM, hammertimedk [email protected] wrote:

I'm seeing this js error pop up sporadically and it's triggered by the line $this.wrap('

').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+"%"); I'm guessing this is when Fitvids wraps my iframe in some responsive magic, and the element then gets recreated on the page, or something like that? In any case, the only reference to this specific error I found online was: https://userscripts.org/topics/124302 - but that doesn't seem right as Fitvids doesn't seem to be referencing the yt variable/object in any way (neither does my code) - so I'm tempted to think this is a bug in Youtube's own js. Can't be sure though. Here you can see it live (dev. site): http://skovstable.nes64.hammerti.me/ As mentioned, the error is sporadic and shows up rather randomly, so I'm also suspecting it has something to do with network/order of execution somewhere, which makes it even harder to pinpoint. Anyhoo, here's hoping you've seen this before and know what this is all

about :)

Reply to this email directly or view it on GitHub: https://github.com/davatron5000/FitVids.js/issues/151

— Reply to this email directly or view it on GitHubhttps://github.com/davatron5000/FitVids.js/issues/151#issuecomment-31393305 .

hammertimedk avatar Dec 31 '13 12:12 hammertimedk

Same problem here. In IE 11 and chrome v33.0.17. It seems to be working ok in FF.

Cheers, Guby

gubagu avatar Feb 28 '14 23:02 gubagu

Any YouTube video on IE11 and Chrome 33? Example?

davatron5000 avatar Feb 28 '14 23:02 davatron5000

Hey davatron5000, Thanks for your fast reaction man ! The weird part is that i checked it today and the error is gone. So i suspect that there is some change in the google embed script. It was ok then it went for the error "yt not defined", and now is good again. At last as much as i can tell. I'll do more test and will share the outcome. I probably just jumped the gun. Thanks for sharing this plugin with us and keep up the good work.

Cheers, Guby

gubagu avatar Mar 01 '14 14:03 gubagu

I'm seeng this happen sporadically as well so that fits with what gubagu reports.

hammertimedk avatar Mar 04 '14 13:03 hammertimedk

If anyone can get a reproducible reduced test case for this, I'll buy you a beer. I've seen it happen but haven't been able to diagnose. Seems irregular and catastrophic. Here are all the possible explanations:

  • CORS/CSP security sort of thing. Browsers flirt with different levels of this all the time.
  • YouTube failure (unlikely)
  • Plugin collisions with YouTube
  • Bad document standards modes (might explain older IEs)
  • Memory leak (for autoplaying videos)
  • jQuery's $.wrap() on an iFrame causes some bugs. Was fixed/updated in jQuery 1.9, I believe.

If it's the last one, we could just require a better version of jQuery.

davatron5000 avatar Mar 04 '14 15:03 davatron5000

Having a similar issue here, embeds on our homepage are acting very sporadically in Chrome (Windows 8). Sometimes they'll work fine, other times it just loads a blank screen, other times there's no content at all. Here's a link http://saraevans.12southdev.com/ Funny thing is its only on our homepage, the video page has been working fine. Videos appear fine in all other browsers too, just funky in chrome.

ian12sm avatar Mar 05 '14 20:03 ian12sm

@ian12sm Blank screen? Hmmmm...

It looks like you haven't upgraded to FitVids 1.1.0, maybe that's the issue. I see in your scripts.min.js that the &shy; character isn't properly encoded and I wonder if that's what is causing the errors. No idea, but 1.1.0 fixes it, then maybe it was that (?!??)

davatron5000 avatar Mar 05 '14 20:03 davatron5000

Will give these a try and come back with the results, thanks!

ian12sm avatar Mar 05 '14 21:03 ian12sm

Could it be because the iframe sometimes hasn't loaded fully, and our call to fitVids is done on documentready? Maybe $(window).load(...) helps.

Experienced it once, first time I loaded my own page. No more...

bjorn-ali-goransson avatar Mar 15 '14 01:03 bjorn-ali-goransson

@bornemix That wasn't the case with my set. I initilize the fitvids on window.load.

gubagu avatar Mar 16 '14 12:03 gubagu

I'm having a similar problem with YouTube embedded in a Bootstrap Modal window. It had been fine and then today, it started giving 'ytcfg is not defined' errors on page load, and on running the video. Using Chrome with Win8.1.

LesAldridge avatar Nov 15 '16 21:11 LesAldridge

@LesAldridge - it is a YouTube failure

  • https://code.google.com/p/gdata-issues/issues/detail?id=8745
  • https://productforums.google.com/forum/#!topic/youtube/3Z7dSnwkCH4

jbruni avatar Nov 27 '16 12:11 jbruni