0

I'm using Firebug lite to debug the HTML elements in JavaFX webview. I'm using the below code.

engine.documentProperty().addListener(new ChangeListener<Document>() {
            @Override public void changed(ObservableValue<? extends Document> prop, Document oldDoc, Document newDoc) {
                enableFirebug(engine);
            }
        }); 
private static void enableFirebug(final WebEngine engine) {
        engine.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', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}");

    }

I have a javascript which will print out the id's and name's of the elements onto firebug console, on every click on different HTML elements. I need to get this console output to my JavaFX application. Please help.

engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
            @Override
            public void changed(ObservableValue<? extends State> observable,
                    State oldValue, State newValue) { 
                JSListener listener = new JSListener();

                JSObject jsobj = (JSObject) engine.executeScript("console.log = function(){"
                        + "var lastElement = null; "
                        + "document.addEventListener('click', function(e) {"
                        + "if (e.target != lastElement) {"
                        + "lastElement = e.target;"
                        + "java.log(lastElement.name);"
                        + "}}"
                        + ");"
                        +"}");                      
                jsobj.setMember("java", listener);  
            }
        });

Java Code :

public class JSListener { 

    public void log(String text) {
        System.out.println(text);
    } 
}

I'm using the below code to get the element ID. Please let me know where I'm going wrong!

2
  • Have you looked at How to get console.log() from javascript to System.out in java? Commented May 19, 2015 at 6:38
  • @ItachiUchiha, thanks for the link. I'm trying to execute similarly. However I'm not getting any output in java console. It would be great if I can catch it into a variable rather than printing on console. I have edited the question and added the code. Please point out my mistake. Commented May 19, 2015 at 6:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.