I am using Spring boot 2.4.4, JDK 1.8, and created ScriptEngine as shown. Page loaded perfectly for the first time but the second time it throws the exception mentioned below.
@Bean
public ScriptEngine scriptEngine() {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("graal.js");
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("polyglot.js.allowAllAccess", true);
bindings.put("polyglot.js.allowHostClassLookup", true);
//engine.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
return engine;
}
org.graalvm.polyglot.PolyglotException: ReferenceError: document is not defined
<js>.:anonymous(<eval>:13)
<js>.:anonymous(<eval>:13)
<js>.r(<eval>:1)
<js>.:anonymous(<eval>:13)
<js>.:anonymous(<eval>:13)
<js>.r(<eval>:1)
<js>.:anonymous(<eval>:13)
<js>.:anonymous(<eval>:13)
<js>.r(<eval>:1)
<js>.:anonymous(<eval>:1)
<js>.:program(<eval>:1)
org.graalvm.polyglot.Context.eval(Context.java:344)
Try to install Java 11+ and latest karate jar