youtube-pause-chrome icon indicating copy to clipboard operation
youtube-pause-chrome copied to clipboard

preventDefault does not prevent spacebar on video

Open selimb opened this issue 9 years ago • 0 comments

I noticed that event.preventDefault() does not prevent the player from switching state when I press spacebar "on" the video.

In other words, if I have a responder that merely does the following:

a = document.getElementsByTagName("body")[0];
responder = function (evt) {
    evt.preventDefault();
    console.log(evt.cancelable);
};
a.onkeydown = responder;

and I put focus on the youtube video and press on the spacebar, the video is still paused/played. However, console tells me that the event is cancelable.

The consequence of this is that pressing spacebar with the extension enabled performs a "double-toggle".

Does anyone know why this happens? The dirty solution would be to not do anything if the event.target is the media player.

selimb avatar Nov 20 '15 18:11 selimb