title: Using javax.script or Rhino to run javascript in Java with browser context (e.g. envjs)?
body: <p>I am trying to run <a href="http://vis.stanford.edu/protovis/" rel="nofollow noreferrer">Protovis</a> javascript from a Java program using <code>javax.script</code>:</p>
  
  <pre><code>ScriptEngineManager factory = new ScriptEngineManager();
  ScriptEngine engine = factory.getEngineByName("JavaScript");
  engine.eval(new java.io.FileReader("protovis-d3.1.js"));
  </code></pre>
  
  <p>In order to run this, the JavaScript engine needs to have all the context of a web browser.  The best option for this seems to be <a href="http://groups.google.com/group/envjs" rel="nofollow noreferrer">envjs</a>.  Unfortunately it seems that the version of Rhino included in the JVM <a href="http://groups.google.com/group/envjs/browse_thread/thread/605ab50e70ad851d" rel="nofollow noreferrer">isn't up to date</a> and doesn't include everything that's necessary for envjs.</p>
  
  <p>Has anyone had any success working with a browser context from javax.script, or am I missing something?</p>
  
  <p>This is related to this question: <a href="https://stackoverflow.com/questions/964392/can-i-create-a-window-object-for-javascript-running-in-the-java6-rhino-script-e">"Can I create a ‘window’ object for javascript running in the Java6 Rhino Script Engine"</a>.</p>