Plyr: getVideoData is not a function

Created on 10 Nov 2017  路  19Comments  路  Source: sampotts/plyr

I've been recently observing a really high number of errors that are happening on our pages and all are within the lines of the following:

data.message:"Uncaught TypeError: n.getVideoData is not a function" data.lineNumber:2 data.columnNumber:809 data.errorMessage:"n.getVideoData is not a function" data.stack:"TypeError: n.getVideoData is not a function
    at onReady ()
    at K.f.I (https://s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:66:267)
    at W.f.l (https://s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:114:67)
    at W.f.J (https://s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:127:281)
    at S.g (https://s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:143:270)
    at g (https://s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:95:28)" data.userAgent:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" data.browser:"Chrome 61.0.3163 / Mac OS X 10.9.5"  

Doing a bit of Google search I found the link you can see below which warns about getVideoData not being a supported function. I can't find it in the docs either. I guess YouTube is releasing a new API version and removing deprecated/unsupported functions yet I can't see it on my machine. I do have several reports though so, it's definitely an issue.

I'd be happy to put time into making a PR with some fix. Let me know if you'd like that.

A quick workaround would be to do a check if the function exists, and it's a function, before actually calling this. This would be beneficial especially if it starts affecting more people.

I've checked and there's no simple way to obtain the title from YouTube, not unless you have an API Key (unless I'm missing something).

Expected behavior

Plyr could try to play safer by checking if getVideoData is defined.

Actual behavior

getVideoData fails some times.

Environment

N/A

Players affected:

  • [ ] HTML5 Video
  • [ ] HTML5 Audio
  • [X] YouTube
  • [ ] Vimeo

Steps to reproduce

Get the video to load. Sometimes that error will pop up.

Relevant links

https://github.com/lunametrics/youtube-google-analytics/issues/36

Most helpful comment

Excellent. Sorry about the issue.

All 19 comments

Yep ! I faced similar situation and i am able to see YouTube Iframe API has removed that function from their list. Not able to see in their deprecation list though :(

Well, it seemed to be an undocumented function which is why they can do as they please without any warning and anytime to roll.

I can confirm the issue with youtube videos

Same thing as of today for me:

s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:121 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://www.youtube.com') does not match the recipient window's origin ('https://sunflowerschoolhouse.tv'). f.C @ s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:121 plyr.js:1 Uncaught TypeError: n.getVideoData is not a function at onReady (plyr.js:1) at K.f.I (s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:66) at W.f.l (s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:114) at W.f.J (s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:127) at S.g (s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:143) at g (s.ytimg.com/yts/jsbin/www-widgetapi-vflnzpyZ4/www-widgetapi.js:95)

facing the same issue in production. For now applied a check for that function in my forked repo.

the same for me since yesterday :(

I have the same problem. How can I fix it?

@jayprakash1 after the fix, does it work with youtube videos?

That's the same fix I suggested. Check if the function is available before using it, should be pretty safe but I'm unsure if that's what @sampotts would want

Yes. Checking function against instance.getVideoData !== undefined ? instance.getVideoData().title : ""; in my forked repo, i can able to work around it. Since, we are passing title attribute while loading, this will not have any impact on playing with youtube videos.

me too instance.getVideoData !== undefined ? instance.getVideoData().title : "";

please how to apply this fix and does it work with YouTube videos?

Sorry fellas, update to v2.0.18 and you should be all good 馃憤

https://github.com/sampotts/plyr/blob/master/src/js/plyr.js#L1771

Thanks heaps!

Excellent. Sorry about the issue.

@sampotts thanks again...

Thanks for the quick fix - with holiday around the corner it's unfortunate Google felt the need to make this change without advance communication to the community regardless of it being undocumented. Let's hope we don't see anymore surprises over the next few months.

Was this page helpful?
0 / 5 - 0 ratings