Got a WebView embedded through a JFXPanel in a Swing app. I'm now trying to get some value back from the WebEngine.executeScript method in a synchronous way.
All examples I can find on Swing embedding use Platform.runLater, which of course doesn't return the value straight away.
Through some digging I found PlatformImpl.runAndWait(Runnable) and when I use that I do get a synchronous call and thus the return value of Webengine.executeScript immediately.
Question now is if it's save for me to use PlatformImpl.runAndWait(Runnable) or if I should refrain from using it for some reason. I wasn't able to find anything on the topic, but so far in my tests if seems to work fine.
Only thing I found were 2 implementations of sort of the same functionality: http://www.guigarage.com/2013/01/invokeandwait-for-javafx/ and https://code.google.com/p/jacp/source/browse/branches/working/JACP.JavaFX/src/main/java/org/jacp/javafx/rcp/worker/AFXComponentWorker.java (invokeOnFXThreadAndWait method)
Using the impl method for run and wait is not advised as it may be removed in a future JavaFX version.
However you can easily copy the source of this simple method to create your own implementation:
See the following thread for details:
Note that in making what is normally an asynchronous call synchronous, you must be careful to avoid deadlock and UI freezing performance issues.