Video.js can accept a video element (or soon a video-js element #4640) as the first argument and it will build the player around the video element or inside that div. However, if the element given to Video.js isn't actually in the DOM nothing will happen and the developer could end up confused as to what is happening.
We should log a warning if the element that is passed to the Video.js method isn't currently included in the DOM.
More information on reproducing is below but to fix it, it will basically involve doing a call to document.body.contains(), which has full browser support, with the element that we received in videojs around here. Then we can log a warning with videojs.log.warn().
If you'd like to work on this, please let us know and please don't work on this if someone else has already claimed it!
// This is the *broken* scenario
var vid = document.createElement('video');
var player = videojs(vid, {});
// We should see a warning logged here
// This scenario should work and not lead to a warning log
var vid = document.createElement('video');
document.body.appendChild(vid);
var player = videojs(vid, {});
If we are passed an element that is not in the DOM, we should log a warning
Nothing currently happens, which could be confusing.
Please include any additional information necessary here. Including the following:
Any
Any
Any
None or any
Very nice description. I'll do this.
Merged the initial PR for the feature but it would be good to add a test to it. Info regarding the test can be found here: https://github.com/videojs/video.js/pull/4698#issuecomment-340815154
Allow me to contribute in it
Oops, sorry, we forgot to close this when the change was merge in. Unfortunately, it's already been done @WaliHassanKhan. thanks for your interest, I hope to have more of these in the future.
That's ok
When working with shadowDOM, this warning is thrown because document.body.contains cannot find element within shadowRoot.
Can you open a new issue about that? A reduced test case would be super helpful.
@WilliamTsao, did you end up posting an issue? I get this with VueJS when providing an element obtained through this.$refs in the mounted callback.
Turns out that $refs aren't accessible in mounted on the first render. You need to wrap your videojs call in:
this.$nextTick(function () { })
Most helpful comment
When working with shadowDOM, this warning is thrown because document.body.contains cannot find element within shadowRoot.