How it's done - J0J0HA/CoatiPython Wiki
CoatiPython is built with pyodide, a project that allows us to interprete python in a browser.
What you need to know and always remember is, that you should never create a infinite loop. The code is executed all at once and the changes are queued, because of python/pyodide running in the same thread as the website does. An infinite loop will make you stuck at the page and you'll have to close and reopen the tab, or even the browser.
Via coati.py we are importing the js-functions and refer them to python, so you can execute it.