GithubHelp home page GithubHelp logo

Growing node.exe memory about hbrowser HOT 6 CLOSED

osiris-team avatar osiris-team commented on July 29, 2024
Growing node.exe memory

from hbrowser.

Comments (6)

Osiris-Team avatar Osiris-Team commented on July 29, 2024

@nocelab can you share the code? I didnt notice anything like that when testing.

from hbrowser.

nocelab avatar nocelab commented on July 29, 2024

this is sample code (Windows 10 with OpenJDK 8u222-b10):

HBrowser hBrowser = new HBrowser();
PlaywrightWindow hb = hBrowser.openCustomWindow().headless(false).buildPlaywrightWindow();

for (int i = 0; i < 100; i++) {
    hb.load("www.google.it");
    hb.fill("[aria-label=\"Cerca\"]", "searching something");
    hb.holdKey("Tab");
    // click and wait...
    hb.getJsContext().executeJavaScript(""+
            "await Promise.all([\n"+
            " page.click(':nth-match(:text(\"Cerca con Google\"), 2)'),\n"+
            " page.waitForNavigation()\n"+
            "]);");
    System.out.println(hb.getOuterHtml().text());
}
hb.close();

and this is memory graph of node.exe process:

image

from hbrowser.

Osiris-Team avatar Osiris-Team commented on July 29, 2024

Ok I tested this code first just to make sure node was working fine by default:

HBrowser hBrowser = new HBrowser();
        try(PlaywrightWindow window = hBrowser.openWindow()){
            window.load("www.google.com");
            System.out.println("Loaded page! Exit the program once finished with ram analysis...");
            while (true)
                Thread.sleep(1000);
        } catch (NodeJsCodeException | InterruptedException e) {
            e.printStackTrace();
        }

image
And it looks good since the node.exe uses only a steady amount of 31mb.

Then I tested your code (slightly modified):

HBrowser hBrowser = new HBrowser();
        try(PlaywrightWindow window = hBrowser.openCustomWindow().headless(false).buildPlaywrightWindow()){
            for (int i = 0; i < 100; i++) {
                window.load("www.google.it");
                window.fill("[aria-label=\"Cerca\"]", "searching something");
                window.holdKey("Tab");
                // click and wait...
                window.getJsContext().executeJavaScript(""+
                        "await Promise.all([\n"+
                        " page.click(':nth-match(:text(\"Cerca con Google\"), 2)'),\n"+
                        " page.waitForNavigation()\n"+
                        "]);");
                System.out.println("Run: "+i);
            }
        } catch (NodeJsCodeException e) {
            e.printStackTrace();
        }

Your code throws following exception:

com.osiris.headlessbrowser.exceptions.NodeJsCodeException: Error during JavaScript code execution! Details: 
CAUGHT JS-EXCEPTION: TimeoutError
MESSAGE: page.fill: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "[aria-label="Cerca"]"
============================================================
LINE: undefined
STACK: page.fill: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "[aria-label="Cerca"]"
============================================================
    at REPL12:2:12
    at REPL12:8:4


	at com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:383)
	at com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:304)
	at com.osiris.headlessbrowser.windows.PlaywrightWindow.fill(PlaywrightWindow.java:711)
	at com.osiris.headlessbrowser.windows.PlaywrightWindow.fill(PlaywrightWindow.java:681)
	at com.osiris.headlessbrowser.issues.Issue9.main(Issue9.java:13)

Process finished with exit code 0

Thus I wasn't able to see the same increase in memory as you since it aborts. Maybe the missing try/catch was somehow your issue?

from hbrowser.

nocelab avatar nocelab commented on July 29, 2024

In my sample nothing goes in exception.
You have to adapt my code with your google.com right localized labels... this graph with your try/catch code:

image

from hbrowser.

Osiris-Team avatar Osiris-Team commented on July 29, 2024

image
Yeah was able to run your code successfully with the same results.
Looked at the java and js code of headless browser and there don't seem to be memory leaks.
I guess its playwright storing the previously loaded pages to allow back and forth navigation.

from hbrowser.

nocelab avatar nocelab commented on July 29, 2024

Ok... I'am happy!
You are right, perhaps something like microsoft/playwright#6319.
I will deepen with Playwright... thanks!

from hbrowser.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.