Headless browser with full javascript support for java
Asked Answered
I

6

33

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?

Interplanetary answered 24/7, 2012 at 15:57 Comment(3)
I'm also in a similar situation. I use HTMLUnit but the JS on some sites don't work on it. Did you find an alternative that works?Grow
Clearly no one provided a solution as none is Java basedRoselleroselyn
@John.which headless browser did you used in your java Application.Culmination
S
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.

Scots answered 1/7, 2013 at 13:28 Comment(0)
P
6

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

(disclosure: I'm the project owner)

Plastometer answered 24/2, 2016 at 7:9 Comment(1)
I am currently using JBrowserDriver for one of my projects as well – I can totally recommend it.Octans
M
4

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

Meetinghouse answered 24/7, 2012 at 16:0 Comment(2)
Is there a Java binding for QtWebKit?Interplanetary
Separate Question or Selenium GhostDriverOlenolin
S
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.

Sufflate answered 24/7, 2012 at 16:18 Comment(0)
R
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.

Reinhard answered 21/1, 2017 at 6:15 Comment(0)
M
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.

Mckoy answered 11/3, 2020 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.