java - For JavaFX's WebEngine, how do I get notified of javascript errors? -
i'm trying run svg contains javascript in javafx's webview. know of scripts i'm trying run have errors , trying figure out how print them console can debug them. i've tried following, weberrorevent never called:
webengine webengine = browser.getengine(); webengine.setonerror(new eventhandler<weberrorevent>() { @override public void handle(weberrorevent event) { system.err.println(event); } });
is right way javascript error feedback control?
setonerror
listener works error while loading given document.
one way solve call java method when console.log
called. can by.
your fx application
webengine engine = mainwebview.getengine(); engine.load("http://whereever.com"); engine.getloadworker().stateproperty().addlistener(new changelistener<worker.state>() { @override public void changed(observablevalue<? extends worker.state> observable, worker.state oldvalue, worker.state newvalue) { jsobject window = (jsobject) engine.executescript("window"); window.setmember("java", new bridge()); engine.executescript("console.log = function(message) { java.log(message); }"); // ever console.log called in html log in java console } });
your bridge class
public class bridge { public void exit() { platform.exit(); } public void log(string text) { system.out.println(text); } }
your html
<h1>text page</h1> <button onclick="java.log('this log')">log</button> <button onclick="console.log('this produces same result above')">console.log</button> <button onclick="java.exit()">exit</button>
hope of help.
Comments
Post a Comment