Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
Accessing Twitch's React video player from an addon/extension

I wanted to create buttons that change stream qualities on Twitch to make it easier instead of clicking three times (settings icon -> quality -> specific quality).

I decided to take care of the addon/extension stuff later and did everything in a user script within ViolentMonkey to develop, and thought that just adding that script as an entry of content_scripts in the manifest would make it work as an extension, but to my surprise, the function can't find the react properties to find the 'real video player'.

The code I'm using to grab the video player is this one:

    function findPlayer() {
        try {
            let videoPlayer = null;
            function findReactNode(root, constraint) {
                if (root.stateNode && constraint(root.stateNode)) {
                    return root.stateNode;
                }
                let node = root.child;
                while (node) {
                    const result = findReactNode(node, constraint);
                    if (result) {
                        return result;
                    }
                    node = node.sibling;
                }
                return null;
            }

            let reactRootNode = null;
            let rootNode = document.querySelector('#root');

            if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) {
                reactRootNode = rootNode._reactRootContainer._internalRoot.current;
            }

            videoPlayer = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance);
            videoPlayer = videoPlayer && videoPlayer.props && videoPlayer.props.mediaPlayerInstance ? videoPlayer.props.mediaPlayerInstance : null;

            if (videoPlayer) {
                return videoPlayer;
            }
        }
        catch(err) {
            console.log(err);
        }
    }

I noticed that when I tried to run the extension, it wouldn't do anything, so, after some debugging, I found out that while rootNode returns successfully, in a user script it has all the following properties, but when in an extension, it lacks the last two, it goes from defineGetter to proto and that's it.

__defineGetter__
__defineSetter__
__lookupGetter__
__lookupSetter__
__proto__
__reactContainer$dbrtyzpjr3t
_reactRootContainer <-- what I need

I even tried to search for _reactRootContainer directly, but there aren't many results from this, and none useful, also, tried to find other ways to meddle with react internal stuff from this post: React - getting a component from a DOM element for debugging, which it doesn't return anything as well.

Anyone has any idea on how to get the video player, it doesn't need to be through this method, anything that I could use to do videoPlayer.setQuality and such.

Thanks a lot in advance!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda