32

I have been using HtmlUnit (the developers did a great job) as an headless browser for some of my previous applications but the javascript support isn't working for some website that my next application will be accessing.

  1. I heard about QtWebKit binding for Python but my application will be in Java or is there a Java binding for WebKit or QtWebKit?

  2. Does anyone know a good headless browser for Java with full javascript support?

John
  • 1,699
  • 5
  • 20
  • 29

6 Answers6

10

Nathan Ridley's answer to another similar question is the most complete one I've found so far.

Anyway, if everything fails, you could use a Python or JS alternative, expose its funcionality as a webservice inside your server, and then your Java application could use the headless browser's funcionality through the webservice. It would be a pain to set up, but it may be a viable alternative if nothing else works as desired.

Also, there are some "non-headless" browser wrappers for Java; maybe it would be possible to build a testing solution around those, depending on the requirements.

Community
  • 1
  • 1
Haroldo_OK
  • 6,612
  • 3
  • 43
  • 80
6

Perhaps https://github.com/machinepublishers/jbrowserdriver -- it's headless and written only in Java.

(disclosure: I'm the project owner)

Dan
  • 736
  • 8
  • 12
4

Take a look at phantom.js. Based on webkit it offers a complete headless browser.

Sirko
  • 72,589
  • 19
  • 149
  • 183
3

Rhino + env.js is a full java solution, I've used it, it's not super fast but seems reasonably stable and should give you correct js support.

Simone Gianni
  • 11,426
  • 40
  • 49
1

Replying on an old thread, hoping it might be useful for some.

1) You can use QTJambi's QWebView. It was reasonably fast.

2) JBrowserDriver is another option.

Personally I found QT engine a bit faster.

0

How about a built-in webview. I'm not sure about full JS support, but a quick check on the website shows that it can support javascript.

JavaFX WebView: JFX WebView


     private static void initWebView(Stage primaryStage) {
        primaryStage.setTitle("JavaFX WebView Example");
        WebView webView = new WebView();
        //webView.getEngine().load("http://localhost:9009");
        webView.getEngine().loadContent("<h3 id='aa'>JAVA FX WebView, HelloWorld</h3><script>document.getElementById('aa').innerHTML='TEST'</script>");
        webView.getEngine().setJavaScriptEnabled(true);
        VBox vBox = new VBox(webView);
        Scene scene = new Scene(vBox, 960, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

And not related to the question, but also take a look at this: Java-Express or NanoHttpd

The combination may help somebody.

Morteza Asadi
  • 414
  • 3
  • 13
Shamshirsaz.Navid
  • 2,224
  • 3
  • 22
  • 36