Puppeteer/Playwright in Java. High-Level headless browser.

Overview

HBrowser

Another headless browser for Java with Puppeteer and Playwright implemented. Add this to your project with Maven/Gradle/Sbt/Leinigen (Java 8 or higher required).

HBrowser hBrowser = new HBrowser();
try(PlaywrightWindow window = hBrowser.openWindow()){
    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.

Features

  • High-Level methods for downloading files, working with cookies, retrieving HTML and simulating real user input.
  • Easy access to Node.js from within Java.
  • HTML handling via Jsoup and JSON with Gson.

Drivers

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 Version JS-Engine Downloads
Playwright Latest Node.js/V8 Yes
Puppeteer Latest Node.js/V8 No

(JS = JavaScript; Downloads = If the browser is able to download files other than html/xml/pdf;)

Contribute/Build

Libraries

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
Comments
  • java.lang.RuntimeException: java.lang.Exception: node.exe couldn't be found in

    java.lang.RuntimeException: java.lang.Exception: node.exe couldn't be found in

    import com.osiris.headlessbrowser.HBrowser; import com.osiris.headlessbrowser.windows.PlaywrightWindow;

    public class Main { public static void main(String[] args) { HBrowser hBrowser = new HBrowser(); try (PlaywrightWindow window = hBrowser.openWindow()) { window.load("https://example.com"); System.out.println(window.getInnerHtml()); } catch (Exception e) { e.printStackTrace(); } } }

    Error during installation of NodeJS. Details: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Exception: node.exe couldn't be found in D:\Projects\WebDriverPleaseWork\headless-browser\node-js\download.zip at com.osiris.headlessbrowser.windows.PlaywrightWindow.(PlaywrightWindow.java:192) at com.osiris.headlessbrowser.windows.WindowBuilder.buildPlaywrightWindow(WindowBuilder.java:79) at com.osiris.headlessbrowser.HBrowser.openWindow(HBrowser.java:30) at Main.main(Main.java:7) Caused by: java.lang.RuntimeException: java.lang.Exception: node.exe couldn't be found in D:\Projects\WebDriverPleaseWork\headless-browser\node-js\download.zip at com.osiris.headlessbrowser.js.contexts.NodeContext.(NodeContext.java:151) at com.osiris.headlessbrowser.windows.PlaywrightWindow.(PlaywrightWindow.java:58) ... 3 more Caused by: java.lang.Exception: node.exe couldn't be found in D:\Projects\WebDriverPleaseWork\headless-browser\node-js\download.zip at com.osiris.headlessbrowser.js.contexts.NodeContext.(NodeContext.java:144) ... 4 more

    Process finished with exit code 0

    opened by empty-person 8
  • Growing node.exe memory

    Growing node.exe memory

    Hi, in Windows machine I'm testing a loop with 2 load method with Playwright browser and I note that the process node.exe still grow without ever release. Is it correct? Is there some trick to release it?

    opened by nocelab 6
  • java.lang.RuntimeException: java.io.IOException: Stream closed

    java.lang.RuntimeException: java.io.IOException: Stream closed

    Error during start of NodeJS! Details:

    java.lang.RuntimeException: java.io.IOException: Stream closed java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: Stream closed at com.osiris.headlessbrowser.js.contexts.NodeContext.(NodeContext.java:164) at com.osiris.headlessbrowser.windows.PlaywrightWindow.(PlaywrightWindow.java:56) at com.osiris.headlessbrowser.windows.WindowBuilder.buildPlaywrightWindow(WindowBuilder.java:81) Caused by: java.lang.RuntimeException: java.io.IOException: Stream closed at com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:436) at com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:342) at com.osiris.headlessbrowser.js.contexts.NodeContext.(NodeContext.java:149) ... 87 more Caused by: java.io.IOException: Stream closed at java.base/java.lang.ProcessBuilder$NullOutputStream.write(ProcessBuilder.java:442) at java.base/java.io.OutputStream.write(OutputStream.java:157) at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81) at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142) at com.osiris.headlessbrowser.js.contexts.NodeContext.writeLine(NodeContext.java:327) at com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScriptFromFile(NodeContext.java:512) at com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:401) ... 89 more

    opened by rofleksey 2
  • Click with promise.All

    Click with promise.All

    I'm testing site navigation with Playwright codegen mode (https://playwright.dev/docs/codegen) and I note that some click produce something like:

    await Promise.all([
       page.click('text=Confirm'),
       page.waitForNavigation(),
    ]);
    

    I have a spefic page where this is importat because of some async RestAPI calls. How could be handle it with HBrowser?

    opened by nocelab 2
  • Two suggestions: screenshots, and table-of-features

    Two suggestions: screenshots, and table-of-features

    I suggest two things:

    (1) add screenshots, no matter how incomplete it is so far, ideally of some simple website, and then perhaps also at some later point a more complicated web site

    (2) for attracting devs, I'd recommend a table of implemented (and missing) features. That way people can quickly look at what needs work and can invest a little bit of time perhaps when they see amount of work required for this or that feature

    Just two suggestions! Please feel free to ignore this or close it at any moment in time for any reason.

    opened by rubyFeedback 1
  • Cause: java.io.IOException: Stream closed (in NodeContext)

    Cause: java.io.IOException: Stream closed (in NodeContext)

    [29-03-2022 09:11:58][SPPU][WARN] Cause-Stacktrace: [29-03-2022 09:11:58][SPPU][WARN] com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:398) [29-03-2022 09:11:58][SPPU][WARN] com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:304) [29-03-2022 09:11:58][SPPU][WARN] com.osiris.headlessbrowser.js.contexts.NodeContext.(NodeContext.java:195) [29-03-2022 09:11:58][SPPU][WARN] com.osiris.headlessbrowser.windows.PlaywrightWindow.(PlaywrightWindow.java:57) [29-03-2022 09:11:58][SPPU][WARN] com.osiris.headlessbrowser.windows.WindowBuilder.buildPlaywrightWindow(WindowBuilder.java:75) [29-03-2022 09:11:58][SPPU][WARN] com.osiris.SPPU.plugins.TaskPluginsUpdater.runAtStart(TaskPluginsUpdater.java:285) [29-03-2022 09:11:58][SPPU][WARN] com.osiris.betterthread.BetterThread.run(BetterThread.java:153)

    opened by Osiris-Team 0
  • .dyml files saved on windows produce wrong values because of \r\n

    .dyml files saved on windows produce wrong values because of \r\n

    Example .dyml file saved on windows:

    key value\r\n
    

    Expected value: value Actual value: value\r

    Note that \r and \n stand for carriage return and next line, and are invisible chars also called control chars.

    opened by Osiris-Team 0
  • Fix error on NodeWindow close

    Fix error on NodeWindow close

    Executing following JS-Code: await browser.close();
    Writing line to NodeJS context: .load D:\Coding\JAVA\Headless-Browser\NodeJS-Installation\node-v16.10.0-win-x64\temp-1040366024.js
    [Node-JS-ERROR] Error: glob dependency not found, set `options.disableGlob = true` if intentional
    [Node-JS-ERROR]     at defaults (D:\Coding\JAVA\Headless-Browser\node_modules\rimraf\rimraf.js:42:11)
    [Node-JS-ERROR]     at rimraf (D:\Coding\JAVA\Headless-Browser\node_modules\rimraf\rimraf.js:60:3)
    [Node-JS-ERROR]     at node:internal/util:363:7
    [Node-JS-ERROR]     at new Promise (<anonymous>)
    [Node-JS-ERROR]     at rimraf (node:internal/util:349:12)
    [Node-JS-ERROR]     at ChildProcess.<anonymous> (D:\Coding\JAVA\Headless-Browser\node_modules\puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:99:21)
    [Node-JS-ERROR]     at Object.onceWrapper (node:events:510:26)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9] > > > > > > > Uncaught:
    [Node-JS-ERROR]     at ChildProcess.emit (node:events:390:28)
    [Node-JS-ERROR]     at ChildProcess.emit (node:domain:537:15)
    [Node-JS-ERROR]     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9] Error: glob dependency not found, set `options.disableGlob = true` if intentional
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at defaults (D:\Coding\JAVA\Headless-Browser\node_modules\rimraf\rimraf.js:42:11)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at rimraf (D:\Coding\JAVA\Headless-Browser\node_modules\rimraf\rimraf.js:60:3)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at node:internal/util:363:7
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at new Promise (<anonymous>)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at rimraf (node:internal/util:349:12)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at ChildProcess.<anonymous> (D:\Coding\JAVA\Headless-Browser\node_modules\puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:99:21)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at Object.onceWrapper (node:events:510:26)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at ChildProcess.emit (node:events:390:28)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at ChildProcess.emit (node:domain:537:15)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9]     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
    [com.osiris.headlessbrowser.NodeContext@61cc61f9] > 
    
    Process finished with exit code 0
    
    
    opened by Osiris-Team 0
  • Fix NodeJs issues

    Fix NodeJs issues

    Initialising NodeJS... SUCCESS!
    Node-JS was started from: C:\Coding\Java\Headless-Browser\NodeJS-Installation\node-v16.10.0-win-x64\node.exe
    Writing line to NodeJS context: const executeJavaScriptAndGetResult = null;
    [NPM-INSTALL] Installing 'puppeteer'...
    [Node-JS] Welcome to Node.js v16.10.0.
    [Node-JS] Type ".help" for more information.
    [Node-JS] > > > undefined
    [NPM] 
    [NPM] up to date, audited 95 packages in 2s
    [NPM] 
    [NPM] 9 packages are looking for funding
    [NPM]   run `npm fund` for details
    [NPM] 
    [NPM] found 0 vulnerabilities
    [NPM-INSTALL] Installed 'puppeteer' successfully!
    START ===>
    // Writing line(s) to NodeJS context:
    const puppeteer = require('puppeteer');const browser = await puppeteer.launch();
    const page = await browser.newPage();
    
    END <===
    Writing line to NodeJS context: await page.goto('https://example.com');
    START ===>
    // Writing line(s) to NodeJS context:
    executeJavaScriptAndGetResult = function() {
    var result = await page.evaluate(() => document.body.innerHTML);
    var fs = require('fs')
    fs.writeFile('C:\Coding\Java\Headless-Browser\NodeJS-Installation\node-v16.10.0-win-x64\executeJavaScriptAndGetResult.txt', result, err => {
      if (err) {
        console.error(err)
        return
      }
      //file written successfully
    })
    };executeJavaScriptAndGetResult();executeJavaScriptAndGetResult = null;
    END <===
    <html>
     <head></head>
     <body></body>
    </html>
    [Node-JS] > > > > > > Uncaught TypeError: Cannot read properties of undefined (reading 'newPage')
    [Node-JS]     at REPL5:1:53
    [Node-JS] > > > > > > ... ... ... ..... ....... ....... ....... ..... ..... ... Uncaught SyntaxError: 
    [Node-JS] var result = await page.evaluate(() => document.body.innerHTML);
    [Node-JS]                    ^
    [Node-JS] 
    [Node-JS] Unexpected token 'p'
    [Node-JS] > > Uncaught TypeError: Cannot read properties of undefined (reading 'goto')
    [Node-JS]     at REPL8:1:35
    [Node-JS] > undefined
    
    
    opened by Osiris-Team 0
Releases(2.4.2)
Owner
Osiris-Team
Cooking some delicious code...
Osiris-Team
Playwright is a Java library to automate Chromium, Firefox and WebKit with a single API.

Playwright is a Java library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.

Microsoft 634 Jan 8, 2023
This is an experiment project I used to learn more about UI Automation with Playwright

Automated Wordle using Playwright (Java) This is an experiment project I used to learn more about UI Automation with Playwright. What's in this reposi

Tom Cools 4 Jan 30, 2022
High-level contextual steps in your tests for any reporting tool

Xteps High-level contextual steps in your tests for any reporting tool. License Maven Central Javadoc Xteps Xteps Allure Xteps ReportPortal How to use

Evgenii Plugatar 8 Dec 11, 2022
A sample repo to help you clear browser cache with Selenium 4 Java on LambdaTest cloud. Run your Java Selenium tests on LambdaTest platform.

How to clear browser cache with Selenium 4 Java on LambdaTest cloud Prerequisites Install and set environment variable for java. Windows - https://www

null 12 Jul 13, 2022
A browser automation framework and ecosystem.

Selenium Selenium is an umbrella project encapsulating a variety of tools and libraries enabling web browser automation. Selenium specifically provide

Selenium 25.5k Jan 7, 2023
🔌 Simple library to manipulate HTTP requests/responses and capture network logs made by the browser using selenium tests without using any proxies

Simple library to manipulate HTTP requests and responses, capture the network logs made by the browser using selenium tests without using any proxies

Sudharsan Selvaraj 29 Oct 23, 2022
Clear browser cache by running Selenium tests with JUnit on LambdaTest cloud.

Run Selenium Tests With JUnit On LambdaTest (Browser Cache Clearing Example) Blog ⋅ Docs ⋅ Learning Hub ⋅ Newsletter ⋅ Certifications ⋅ YouTube      

null 16 Jul 11, 2022
Distributed, masterless, high performance, fault tolerant data processing

Onyx What is it? a masterless, cloud scale, fault tolerant, high performance distributed computation system batch and stream hybrid processing model e

Onyx 2k Dec 30, 2022
A Java architecture test library, to specify and assert architecture rules in plain Java

ArchUnit is a free, simple and extensible library for checking the architecture of your Java code. That is, ArchUnit can check dependencies between pa

TNG Technology Consulting GmbH 2.5k Jan 2, 2023
HATEOAS with HAL for Java. Create hypermedia APIs by easily serializing your Java models into HAL JSON.

hate HATEOAS with HAL for Java. Create hypermedia APIs by easily serializing your Java models into HAL JSON. More info in the wiki. Install with Maven

null 20 Oct 5, 2022
Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java

Scott Test Reporter for Maven and Gradle Get extremely detailed failure messages for your tests without assertion libraries, additional configuration

Dávid Csákvári 133 Nov 17, 2022
TCP Chat Application - Java networking, java swing

TCP-Chat-Application-in-Java TCP Chat Application - Java networking, java swing Java – Multithread Chat System Java Project on core Java, Java swing &

Muhammad Asad 5 Feb 4, 2022
A sample repo to help you handle basic auth for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to handle basic auth for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - htt

null 12 Jul 13, 2022
A sample repo to help you run automation test in incognito mode in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to run automation test in incognito mode in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - htt

null 12 Jul 13, 2022
A sample repo to help you handle cookies for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to handle cookies for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - https:

null 13 Jul 13, 2022
A sample repo to help you set geolocation for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to set geolocation for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows - https

null 12 Jul 13, 2022
A sample repo to help you capture JavaScript exception for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to capture JavaScript exception for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Wi

null 12 Jul 13, 2022
A sample repo to help you find an element by text for automation test in Java-selenium on LambdaTest. Run your Java Selenium tests on LambdaTest platform.

How to find an element by text for automation test in Java-selenium on LambdaTest Prerequisites Install and set environment variable for java. Windows

null 12 Jul 13, 2022