Html/Javascript debugging in JavaFX WebView


Question

Are there any ways to debug javascript and html that is executed within a Javafx WebView? Something similar to Firebug or Chrome's developer console?

I have an application that renders fine in Firefox and Chrome, but does not render correctly inside a WebView. It really could be any number of things, but without some debugging tools I don't know how to track down the root cause.

Thanks.

1
27
2/22/2012 4:30:29 PM

Accepted Answer

Here is some Java code to make use of Firebug Lite in a JavaFX WebView without modifying the html of the target page.

webView.getEngine().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');}"); 

You can trigger the code using a JavaFX Button or any other mechanism you wish.

33
2/23/2012 1:10:15 AM

I am debugging JavaFx WebView with chrome DevTools and safari Web Inspector.

I created minimal project to help people debug with DevTools. Get it on GitHub. You can find there:

  1. runnable javaFXWebKitDebugger.jar
  2. source code of created javaFXWebKitDebugger.jar

The sample opens WebView and enables WebSocket Servlet. When you run javaFXWebKitDebugger.jar open Chrome browser and load: dev tools url


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon