JDK-8091505 : Add Nashorn API to a WebView
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 7u45
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2013-11-22
  • Updated: 2020-10-27
  • Resolved: 2020-05-01
Related Reports
Relates :  
Relates :  
Description
At the moment Nashorn API (http://download.java.net/jdk8/docs/technotes/guides/scripting/nashorn/api.html) is not available in a WebView. A try to run this:

    System.out.println(browser.getEngine().executeScript("Java.type(\"java.lang.Math\").PI"));


Would lead to JSException:

netscape.javascript.JSException: ReferenceError: Can't find variable: Java
	at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:128)
	at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
	at com.sun.webkit.WebPage.executeScript(WebPage.java:1410)
	at javafx.scene.web.WebEngine.executeScript(WebEngine.java:934)

Adding Nashorn API would simplify running Java code in a WebView and make easier the development of desktop applications using JavaScript frameworks like AngularJS, Twitter Bootstrap, PhoneGap, etc. Though it is possible at the moment, it requires adding boilerplate code and JavaScript-to-Java call workarounds, i.e. serializing complex objects to JSON.
Comments
Nashorn has been removed. Closing as Won't fix.
01-05-2020

Or JDK 8.X. Also support for asm.js and WebGL should be considered.
18-03-2014

It would be great to have this for more extensive support for popular JS frameworks.
22-11-2013

Something that could be considered for a future version (e.g., JDK 9).
22-11-2013