How to get the JavaFx WebEngine to report errors in detail?

Tony Eastwood picture Tony Eastwood · Mar 20, 2013 · Viewed 9.7k times · Source

In JavaFx I can attach a listener to the load worker for a webEngine like this:

 webEngine.getLoadWorker().stateProperty().addListener(
      new ChangeListener<Worker.State>() {
      public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {                               
             System.out.println("webEngine result "+ newState.toString());
      }
  });

However if I try to load a document at an https address such as:

https://SomeLocalMachine.com:9443/jts/admin#action=com.ibm.team.repository.manageUsers

all I get printed out on the console is:

webEngine result READY
webEngine result SCHEDULED
webEngine result RUNNING
webEngine result FAILED

(The same https address in Firefox or Chrome gets me a login page)

Does anyone know how I can get more detailed reports out of the JavaFx WebEngine. I don't want to just know that it failed - I need to know why. I can guess my error is SSL/certificate/HTTPS related but currently I'm quite in the dark as to which part of SSL caused it to 'FAIL'

Answer

Marcin Fatyga picture Marcin Fatyga · Jun 10, 2016

You can use com.sun.javafx.webkit.WebConsoleListener. Downside is that it is JRE internal API.

WebConsoleListener.setDefaultListener(new WebConsoleListener(){
    @Override
    public void messageAdded(WebView webView, String message, int lineNumber, String sourceId) {
        System.out.println("Console: [" + sourceId + ":" + lineNumber + "] " + message);
    }
});