Is there a way to embed a browser in Java? more specifically, is there a library that can emulate a browser?
-
JxBrowser library provides Swing/JavaFX lightweight component based on the latest Chromium engine. The web pages are rendered by Chromium engine off-screen and displayed in the lightweight Swing/JavaFX component. It's very easy to use. It's free for Open-Source and Academic projects.– VladimirSep 12, 2016 at 19:42
-
i thought, it is commercial. I mean how could you get the free license @Vladimir ?– gumuruhJan 25, 2017 at 2:33
-
In the evaluation form at teamdev.com/jxbrowser#evaluate, select Open-Source or Academic. You will see short explanation: The evaluation licence will not work after this time. If you are doing an open source project, you can request a permanent licence via the link provided in the email you will receive. So, once you request evaluation, you will get an email you can write to to request a free license for open-source project.– VladimirJan 25, 2017 at 16:28
15 Answers
Since JavaFX 2.0 you can use now webview
-
1
-
An alternative JavaFX library is JxBrowser with BrowserView component: teamdev.com/jxbrowser– VladimirApr 17, 2015 at 13:58
-
WebView has some performance issues, see stackoverflow.com/questions/10762979/…– StefanJan 18, 2017 at 6:15
-
shitty thing ever possible. worst performance, javascript seldom works, unwanted behavior. Can never be used in any good project Aug 7, 2017 at 14:42
-
Just tried out WebView (Jan 9, 2021), and it is now very performant! (on macOS) Very nice overall and I think I will be making GUIs via this method (also lets me embed nice javascript widgets) Jan 9, 2021 at 20:57
I believe JWebPane is going to be the official way to embed a browser into a java app. Its based on the open sourced engine - WebKit, which is used in Apples Safari and Googles Chrome browsers.See this blog for details.
-
1JWebPane shows no signs of activity/life... However mozswing seems to work pretty well. I tried the JNLP download version and it the page renders well. Memory usage is a high, but support for web standards is good as it is based on the Mozilla browser. Available at confluence.concord.org/display/MZSW/Home Feb 5, 2010 at 0:40
-
1As of april 2010, this is not possible. It seems JWebPane is vaporware :( Apr 29, 2010 at 16:37
-
1April 2011, almost, still no sign, just like JMF too, for video mission is like mission impossible. Firefox 4 is launched yesterday.– user285594Mar 23, 2011 at 18:14
-
22Update JWebPane changed into WebView in JavaFX 2.0 ( the libraries series ) See: download.oracle.com/javafx/2.0/webview/jfxpub-webview.htm for a sample screenshot of it running see: javamexico.org/blogs/oscarryz/webview_en_javafx ( not written in Java though but in a experimental JVM language )– OscarRyzJun 14, 2011 at 21:44
-
3Is WebView in JavaFX truly standalone cross platform or does it depend on any platform specific native components? More importantly, how does it stack up to rendering pages? It is powered by WebKit but is this as close to having a real browser when it comes to rendering websites?– KJWMay 7, 2012 at 1:34
You may try this: https://jdic.dev.java.net/
(source: java.net)
Or this: http://lobobrowser.org/java-browser.jsp
(source: lobobrowser.org)
-
Its very good to have something atleast. But its very slow and the graphics is very bad compared to Chrome or Firefox 4– user285594Mar 23, 2011 at 17:49
-
-
@OzhanDuz any details about JDIC issues? I like the approach, but haven't used it myself yet. Aug 21, 2012 at 6:36
-
Stay away from JDIC, its not multiplatform, i am not sure but development might be stopped or not active. Use DJ Native Swing, you will get regular updates, better api and more stable.– user452425Aug 21, 2012 at 10:27
You could use SWT for your GUI. Its Browser control allows you to embed IE, Mozilla or Safari (depending on the platform you're running in) with little pain.
-
The return values of browser.evaluate() are limited to a view types. The JavaFx WebEngine can handle all kinds of return types by wrapping the return value in JSObject.– StefanJan 18, 2017 at 6:17
By far the most robust embeddable browser I am familiar with is the one in SWT. In fact, it is so flexible that the JavaDoc hover you can see in Eclipse is actually a browser, and the JavaDoc view actually supports things like animation!
The only risk with using SWT is that there are different versions of the SWT library for different platforms. I'm not sure if there is a singl jar you could include to cover everyone.
JxBrowser has not been mentionned yet. It embed either Mozilla Firefox (Gecko), Apple Safari (WebKit) or Internet Explorer. Programmer's Guide
-
-
2Starting from 4.0 version JxBrowser integrates with Chromium engine.– VladimirDec 6, 2013 at 11:02
-
I've been looking for a real answer to this question for years, and JxBrowser version 4 is really a game changer. It is exactly what you'd hope a swing browser component would be.– CarlGApr 8, 2014 at 22:19
-
1
You could also try the JWebBrowser from DJ Native Swing: http://djproject.sourceforge.net/ns
I have successfully opened a browser from Java using SWT. You can find code examples of how to use SWT to open a Browser window. It's very easy to do.
-
The return values of browser.evaluate() are limited to a view types. The JavaFx WebEngine can handle all kinds of return types by wrapping the return value in JSObject– StefanJan 18, 2017 at 6:18
You can embed a browser in a Swing/AWT GUI using the JDIC API. I don't see any mention of OS X, so it may not be of use to you.
You can try Webrenderer or Ice Browser
-
Ice Browser is not actually sold anymore, the product has reached End of Life Jun 23, 2009 at 15:50
If you need a pure Java solution then you can try JWebEngine. It render HTML 4 very good. You can use it in an applet, Java webstart and on any platform. The using is very simple.
-
However, it is not an open source solution. It might not fit all needs. Feb 23, 2011 at 6:22
-
You could try a JEditorPane
, it doesn't interpret advanced HTML, nor Javascript, nor advanced CSS, but you can write that part yourself, called the EditorKit
. That is the class/object that is consulted by the JEditorPane or how it has to display its content.
I know its possible, because I tried and failed (:P), but it could be outdated or deprecated by now, I don't know.
Maybe Chromium Embedded Framework is an option for you. Specific to Java there is
javacef for SWT: https://github.com/wjywbs/javacef
java-cef for AWT: https://bitbucket.org/chromiumembedded/java-cef
If you look at The Minecraft launcher (the old one), look through LoginForm or LauncherFrame, you may be able to find out that method. There is a tutorial by kippykip on youtube on how to decompile and edit it: here