Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!