4

I am currently working on getting JavaScript to execute successfully from within Python. I have implemented a JS engine (v8) using the PyV8 package. From here I can execute primitive JavaScript ("1+2", etc). However, for JavaScript that uses references to "document" or "window" the code will throw an error. I am looking, ideally, for a Python implementation however a JavaScript implementation would work as well as I could prepend it to my script before executing it what my JavaScript engine.

To summarize: How can I execute JavaScript, that uses 'Document' and/or 'Window', from within JavaScript?

1
  • Hey Louis, I suggest looking over the questions you've asked and if any have satisfactory answers, consider making an answer as accepted by clicking the checkmark. You get magic points and everyone is more happy. Commented Jul 5, 2010 at 20:47

1 Answer 1

3

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

And how would I tie this into my Python application? It states on the Env-JS website that there are Python bridges, but I am unable to locate any.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.