Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate DOM for Rhino / Java 6 script engine

When using Rhino / Java 6's script engine:

ScriptEngine engine = manager.getEngineByName("JavaScript");

My problem is when I evaluate some scripts (normally written for the browser environment) the script engines crashes, due to "window" is not defined, which I fully understand since DOM is something created browser browsers.

However, what is the best way to simulate/mock the DOM environment (for example the "window" object).

Can this be done in Java (for example enabling something in ScriptEngine / Java) or do I have to include some kind of JavaScript that simulates the DOM?

What is currently the best solution to simulate this for Rhino/ Java 6 script engine?

like image 265
corgrath Avatar asked Jul 06 '26 15:07

corgrath


1 Answers

The DOM is a HUGE environment. A complete simulation of everything in a browser is probably not available. HOWEVER, take a look at Bringing the Browser to the Server. If this has been maintained, it may be enough for your purposes.

like image 195
Jim Garrison Avatar answered Jul 09 '26 06:07

Jim Garrison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!