4 Replies Latest reply on Jul 27, 2013 2:06 AM by jsmith

    use webengine without webview

      hi all
      can webengine be used without webview?
      I want to use it as a headless browser to test webpages with javascript in linux without X server. is it possible? Thanks.
        • 1. Re: use webengine without webview
          Not to avoid your question or steer anyone away from javafx, but Phantom JS runs without X server since 1.5: http://phantomjs.org/faq.html

          You could use this, or something like casper.js( http://casperjs.org/ ) which builds on it, to do what you want, unless you are specifically needing a java/javafx solution.

          I'm actually interested in the answer to your question myself for other potential uses, so hope someone who can answer it chimes in.
          • 2. Re: use webengine without webview
            WebEngine can work without WebView as demonstrated in the following sample:
            import javafx.application.Application;
            import javafx.beans.value.*;
            import javafx.scene.Scene;
            import javafx.scene.control.TextArea;
            import javafx.scene.web.WebEngine;
            import javafx.stage.Stage;
            import org.w3c.dom.Document;
            public class HeadlessWebEngine extends Application {
              @Override public void start(Stage stage) {
                final TextArea docString = new TextArea();
                final WebEngine engine = new WebEngine();
                engine.documentProperty().addListener(new ChangeListener<Document>() {
                  @Override public void changed(ObservableValue<? extends Document> observable, Document oldDoc, Document newDoc) {
                    docString.setText((String) engine.executeScript("document.documentElement.innerHTML"));
                stage.setScene(new Scene(docString, 800, 600));
              public static void main(String[] args) { launch(args); }
            Whether you could "use it as a headless browser to test webpages with javascript in linux without X server", I don't know and I don't have the appropriate environment to test it - you would have to try it and see.
            • 3. Re: use webengine without webview

              While your example does not use WebView, it does try to create a window with stage.show().  I've tested and it does err on a server without an X server.

              Actually, even if you comment out stage.show() it still errs.


              I've been trying to find a way to run headless myself, not sure if it is possible.

              • 4. Re: use webengine without webview

                You might be interested in:

                RT-20494 Headless Glass toolkit needs to be connected to Quantum and Prism unit tests.


                It's one of those things currently scheduled for Lombard (Java 8) implementation that I think will be pushed from that least because the release is past feature complete date.


                But maybe there is some headless toolkit already implemented out there that you could just enable if you knew the appropriate command line switch, I don't know.  Though I doubt it - you can only read so much into obscure text in jira issues.


                Similar to:

                RT-31175 permit headless creation of charts


                You could create an issue request to permit headless creation of charts.

                If your lucky, it would get scheduled for an 8.1 release timeframe (e.g. maybe 6-12 months after Java 8 is released).

                It's not an uncommon feature request, and it makes some sense, so there is probably a chance it would make it in 8.1.