It doesn't work when pressing Space right after moving to the tab and right after reloading the tab. To fix it, you need to call the controlVideo(e); from the preventSpaceScroll. Though it would be best if you merged the two functions into a single one, which to check both things.
function preventSpaceScroll(e) {
if (e.code === 'Space' && e.target === document.body) {
e.preventDefault();
controlVideo(e);
}
}
It doesn't work when pressing Space right after moving to the tab and right after reloading the tab. To fix it, you need to call the
controlVideo(e);
from thepreventSpaceScroll
. Though it would be best if you merged the two functions into a single one, which to check both things.