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!