Skip to content

HtmlUnit is failing to load the full external JavaScript #93

@JaviRpo

Description

@JaviRpo

The dependency version that I'm using is

<dependency>
	<groupId>org.junit.jupiter</groupId>
	<artifactId>junit-jupiter-api</artifactId>
	<version>5.5.2</version>
	<scope>test</scope>
</dependency>

The code that I have is:

try (WebClient webClient = new WebClient()) {
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    HtmlPage htmlPage = webClient.getPage("https://www.exito.com/");

    DomNode domNode = htmlPage.querySelector(".menu-categoria");

    System.out.println(domNode); // domNode should not be null
}

After some tests, I realize that the problem is when the page is loading an external JavaScript in the URL https://cdn.polyfill.io/v3/polyfill.min.js?features=Object.keys&flags=gated,always
The problem is because of the JavaScript has in the first line a comment and space in the third character
image

When I debug into the code the JavaScript sourceCode only has the first three characters
image

And this is because the content is reading with BOMInputStream
image

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