andrewvasilchuk / vue-lazy-youtube-video

Vue.js component for lazyloading YouTube videos.
MIT License
102 stars 22 forks source link

Cannot read property '1' of null #4

Closed vanhumbeecka closed 4 years ago

vanhumbeecka commented 5 years ago

Happens when I pass the following YouTube URL: https://www.youtube-nocookie.com/embed/MTk-Hwr15ao.

Does not happen when using a normal YouTube URL, like: https://www.youtube.com/watch?v=2u_pZ-SgACk.

Not sure if this qualifies as a bug or a feature.

unr commented 4 years ago

This is caused by these lines of code:

id() {
  const regExp = /^https:\/\/www\.youtube\.com\/watch\?v=(.+)$/;
  return regExp.exec(this.url)[1];
},

Should be updated like so:

id() {
  try {
    const regExp = /^https:\/\/www\.youtube\.com\/watch\?v=(.+)$/;
    return regExp.exec(this.url)[1];
  } catch (err) {
    throw 'Youtube url in wrong format. Must be written as https://wwww.youtube.com/watch?v=1234';
    return 0;
  }
},
andrewvasilchuk commented 4 years ago

@unr, @vanhumbeecka Thanks. I will change regExp a bit to handle cases with URL that starts with: https://www.youtube-nocookie.com. Also in the next minor version the noCookie prop will be introduced, which will generate appropriate url for the <iframe />.

andrewvasilchuk commented 4 years ago

See 29a6ad58163af163c45ed7f20f461e2028d96b1d.

andrewvasilchuk commented 4 years ago

Notice: you should not pass URL with /embed/ part. Just pass a direct link to the video itself: https://www.youtube.com/watch?v=2u_pZ-SgACk.

andrewvasilchuk commented 4 years ago

@vanhumbeecka, @unr, Fixed in @1.3.0-beta.0. Just pass noCookie prop with true value.

andrewvasilchuk commented 4 years ago

Can we close the issue? 🤔