I'm trying to make kind of wrapper class to create applications that use JavaFX WebView for their GUI (I called the class Application
), that I can easily use in my other apps (I make a jar of my wrapper project, and then jar can be imported in any other project). I assumed that including some debug features in my wrapper is important, so I downloaded 'firebug-lite.js' and 'firebug-lite.css' version 1.2 to ./src/firebug/ directory in my project folder (so no internet required). After a number of tries I came to following code in Application.debug()
:
public void debug() {
// file is inside the jar, in ./firebug/ directory, so I use getResourceAsStream()
BufferedReader br = new BufferedReader(new InputStreamReader(
getClass().getResourceAsStream("/firebug/firebug-lite.js")));
String line;
String wholeFirebugCode = "";
try {
// reading firebug-lite.js line-by-line, not including \n characters
while ((line = br.readLine()) != null) {
wholeFirebugCode += line;
}
if (wholeFirebugCode.isEmpty()) System.out.println("!");
else {
// everything is OK, file is read, so add firebug to our page
engine.executeScript("document.body.innerHTML += \""+
"<script type='text/javascript'>" +
wholeFirebugCode +
"</script>\"");
}
} catch (IOException e) {
printError(e, "during load of /firebug/firebug-lite.js from within jar (WebEngineApp.jar)");
}
}
So, I built a jar, checked whether it has ./firebug/firebug-lite.js (it does), included that jar in a sample project and tried with this code:
// constructor works fine
Application app = new Application("title of window", path_to_sample_html_page,
width, height, bridge);
app.run();
try {//we wait a few til page is fully loaded (just for sure)
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
printError(e, "");
}
// here I check if java-js connection is established and page is loaded. It is
Platform.runLater(app::test);
// here I run the code which cause problem
Platform.runLater(app::debug);
But this doesn't work. I use Java 8, if it makes any difference:
Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: SyntaxError: Unexpected identifier 'css'
at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:146)
at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
at com.sun.webkit.WebPage.executeScript(WebPage.java:1509)
at javafx.scene.web.WebEngine.executeScript(WebEngine.java:1005)
at emeshka.webengineapp.Application.debug(Application.java:157)
at Main.lambda$main$0(Main.java:41)
(... etc)
File seems to be read correctly, I've checked it by logging. Same thing happens if I try to use 'firebug-lite-compressed.js', and if I use this method of code including:
engine.executeScript(wholeFirebugCode);
I'm completely lost. It couldn't be that firebug is syntactically incorrect. Sample html page contains no js. How can I make firebug work? I've tried to use these solutions, that require internet, but they just took no effect, and no errors were shown: Html/Javascript debugging in JavaFX WebView , JAVAFX / WebView / WebEngine FireBugLite or Some other debugger?