Skip to content

htmlunit doesn't register event listener on 'readystatechange' #561

Description

@QIvan

Hi! First of all, thank you very much for this beautiful tool. It's extremely useful, and we use it all over the place in our projects.

Last week we decided to upgrade it from 2.14 to the latest version (yeah-yeah, we didn't rush with it, I know 😄 )
but we noticed that now Htmlunit behaves a bit differently than any browser:

We compose a small HTML:

<html>
    <body>
        <script>
            alert('Initial State:' + document.readyState);
            document.addEventListener('readystatechange', function() {
               alert('Changed:' + document.readyState);
            });
        </script>
    </body>
</html>

I kick it off with python HTTP server like

python3 -m http.server

If I open http://localhost:8000 in my browser (I tested with chrome and firefox)
I will see the next notifications:

  • Initial State:loading
  • Changed:interactive
  • Changed:complete

Now I try to "open" this page with htmlunit:

public static void main(String[] args) throws Exception {
    final WebClient webClient = new WebClient(BrowserVersion.CHROME);
    WebClientOptions webClientOptions = webClient.getOptions();
    webClientOptions.setJavaScriptEnabled(true);
    webClient.setAlertHandler((AlertHandler) (page, message) -> System.out.println(message));

    Page page = webClient.getPage("http://localhost:8000");
    System.out.println("HTMLUnit Doc ready state: "
            + ((HtmlPage) page).getDocumentElement().getReadyState());

}

in the output I see just the following:

Initial State:loading
HTMLUnit Doc ready state: complete

So, correct me if I'm wrong, but it seems like htmlunit didn't create a listener, or it did handle readystatechange some other way as a browser does.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions