How to execute JS from Python, which uses the “Document” and / or “Window”,

I'm currently working on making JavaScript run successfully with Python. I implemented the JS engine (v8) using the PyV8 package. From here I can execute primitive JavaScript ("1 + 2", etc.). However, for JavaScript that uses links to a "document" or "window", the code throws an error. I look, ideally, for a Python implementation, however the JavaScript implementation will work just as I could add it to my script before I execute it, which is my JavaScript mechanism.

To summarize: how can I execute JavaScript, which uses Document and / or Window, from JavaScript?

+3
source share
1 answer

I had the same problem when using Spidermonkey (command line JavaScript interpreter) and trying to run a script that was based on non-existent objects documentand window.

I solved it using the Env-JS project , which sets up independent "fake" objects for them.

+3
source

Source: https://habr.com/ru/post/1753201/


All Articles