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

96
Visualizações
Injecting actual brython code from chrome extension

I have the code taken from Inject a script tag with remote src and wait for it to execute:

function injectScript(src){
    return new Promise((resolve, reject) => {
        const script = document.createElement('script');
        script.src = src;
        console.log(script.src)
        script.setAttribute('type', 'text/javascript');
        script.addEventListener('load', resolve);
        script.addEventListener('error', e => reject(e.error));
        document.head.appendChild(script);
    });
}

By writing

injectScript((chrome.runtime.getURL("/utils.js")))
    .then(() => {
        console.log("script loaded")
    }).catch(error => {
        console.log(error);
    })

I can successfully inject my code from utils.js (below) into an html page which I have verified works with seperately injected html code with a button with onclick="foo()"

function foo(){
    console.log("bar");
}

Now, my question is how do I modify my injectScript function to inject my brython code (below)? I have tried setting the type attribute to text/python but otherwise keeping it the same, but this does not work. Similarly changing script.src = src to script.textContent = src does not work. In all cases, simply nothing happens without an error.

***python.js***

from browser import document, alert

def hello():
    alert("hello world")

document['mybutton'].bind('click', hello)

Edit: Full code used for injecting brython code (console logs 'min script loaded' and 'stdlib script loaded' but not 'python loaded' nor alerts 'hello world':

 injectScript("https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.9/brython.min.js")
    .then(() => {
        console.log('min script loaded!');
        injectScript("https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.5/brython_stdlib.min.js")
            .then(() => {
                console.log('stdlib script loaded!');
                
                injectPython((chrome.runtime.getURL("/python.js")))
                    .then(() => {
                        console.log("python loaded")
                    }).catch(error => {
                    console.log(error)
                })
            }).catch(error => {
                console.error(error);
            });
    }).catch(error => {
        console.error(error);
    });
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