Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda