Headless/full Java browser with support for downloading files, working with cookies, retrieving HTML and simulating real user input. Possible via Node.js with Puppeteer and/or Playwright. Main focus on ease of use and high-level methods. Add this to your project with Maven/Gradle/Sbt/Leinigen (Java 8 or higher required).
try(PlaywrightWindow window = HB.newWin()){
window.load("https://example.com");
// ...
}
All examples here.
Note that the first run may take a bit because Node.js and its modules get installed into your current working dir under ./headless-browser
.
HB.newWinBuilder().headless(true).makeUndetectable(true)...
new NodeContext().executeJavaScript("console.log('Hello!');");
try (PlaywrightWindow w = HB.newWinBuilder()
.headless(true).makeUndetectable(true).buildPlaywrightWindow())
{
w.load("https://infosimples.github.io/detect-headless/");
w.makeScreenshot(new File("screenshot.png"), true);
}
catch (Exception e) {e.printStackTrace();}
Last checked 18.06.2024.
Playwright is the default and recommended browser driver to use, since it supports downloads and more of its features were ported to Java. Checkout JG-Browser for a browser completely written in Java.
Name | JS-Engine | Downloads |
---|---|---|
Playwright | Node.js/V8 | Yes |
Puppeteer | Node.js/V8 | No |
You can find their versions in this class, which also allows you to set custom versions. (JS = JavaScript; Downloads = If the browser is able to download files other than html/xml/pdf;)
If you have never contributed before, we recommend this Beginners Article. If you are planning to make big changes, create an issue first, where you explain what you want to do. Thank you in advance for every contribution! If you don't know how to import a GitHub project, check out this guide: IntelliJ IDEA Cloning Guide
Name/Link | Usage | License |
---|---|---|
Playwright | Emulates different types of browsers | License |
Puppeteer | Emulates different types of browsers | License |
Node.js | Enables executing JavaScript code | License |
Jsoup | Used to load pages and modify their HTML code | License |