I'm using react-player to play youtube videos and have a lot of custom hotkeys defined with react-hotkeys-hook
. I've got the following config which prevents the default youtube key handlers from running:
const PLAYER_CONFIG: Config = {
youtube: {
playerVars: { controls: 0, disablekb: 1, rel: 0 },
},
}
However with this config (or event with disablekb: 0
) the youtube player still swallows all keypress events when it has focus and my custom hotkey handlers don't run. There was a similar issue in the react-player repo back in 2022, closed without resolution.
Is there a way I can get the youtube embedded player to forward these on?
EDIT (things I've tried)
It turns out I can access the internal iFrame in React Player by
<ReactPlayer
onReady={(player) => {
console.log(player.getInternalPlayer()['getIframe']())
}}
// ...
But attempting to .contentWindow.addEventListener(...)
results in a security error:
Uncaught DOMException: Blocked a frame with origin "http://localhost:3000" from accessing a cross-origin frame.
Related?
I'm beginning to think this might not be possible with the youtube iFrame API.
How to add keydown event on iframe while playing youtube video?