Html/Javascript debugging in JavaFX WebView

Are there any ways to debug javascript and html that is executed within a Javafx WebView? Something similar to Firebug or Chrome's developer console?

I have an application that renders fine in Firefox and Chrome, but does not render correctly inside a WebView. It really could be any number of things, but without some debugging tools I don't know how to track down the root cause.




Here is some Java code to make use of Firebug Lite in a JavaFX WebView without modifying the html of the target page.

webView.getEngine().executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', '' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', '' + '#startOpened');}"); 

You can trigger the code using a JavaFX Button or any other mechanism you wish.


I am debugging JavaFx WebView with chrome DevTools and safari Web Inspector.

I created minimal project to help people debug with DevTools. Get it on GitHub. You can find there:

  1. runnable javaFXWebKitDebugger.jar
  2. source code of created javaFXWebKitDebugger.jar

The sample opens WebView and enables WebSocket Servlet. When you run javaFXWebKitDebugger.jar open Chrome browser and load: dev tools url


You can try Firebug Lite, which can be incorporated into any web-browser. See


Maybe a bit late to answer, but I think this way is quite simple.

add javascript listener in java

Java :

webengine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
            public void changed(ObservableValue<? extends State> observable,
                    State oldValue, State newValue) { 
                     JSObject jsobj = (JSObject) webengine.executeScript("window");                      
                     jsobj.setMember("java", new JSListener());  

Then create the JS listener class in java.

JSListener java:

public class JSListener { 

        public void log(String text){

add javascript in html file


var javaReady = function(callback){
    if(typeof callback =='function'){
        if(typeof java !='undefined'){
        } else {
            var javaTimeout = 0;
            var readycall = setInterval(function(){
                if(typeof java !='undefined' || javaTimeout > 1000){
                    } catch(s){};

            var errorlistener = function(msg, url, line){ 
            java.log(msg +", url: "+url+ ", line:" + line); 

      //overide onerror 
        var onerror = errorlistener;

If you want to load html from the outside, you can not to change it, you can use code like this.

var testsss ="");  
testsss.onerror = errorlistener;  

but first you need to add setCreatePopupHandler in java, to make it you can see here: webview not opening the popup window in javafx


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.