use of com.teamdev.jxbrowser.js.ConsoleMessage in project JxBrowser-Examples by TeamDev-IP.
the class JsConsoleEvents method main.
public static void main(String[] args) {
Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("JS Console Listener");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.on(ConsoleMessageReceived.class, event -> {
ConsoleMessage consoleMessage = event.consoleMessage();
System.out.printf("Level: %s\nMessage: %s%n", consoleMessage.level().name(), consoleMessage.message());
});
browser.mainFrame().ifPresent(frame -> frame.executeJavaScript("console.error(\"Error message\");"));
}
Aggregations