HtmlUnit / htmlunit

HtmlUnit is a "GUI-Less browser for Java programs".
https://www.htmlunit.org
Apache License 2.0
848 stars 166 forks source link

How htmlunit supports ES6 ? #767

Open xuxiaowei-com-cn opened 3 months ago

xuxiaowei-com-cn commented 3 months ago

The project I created using Vue/vite/TS cannot load external JS.

23:12:33.326 [main] DEBUG com.gargoylesoftware.htmlunit.util.EncodingSniffer - Encoding found in meta tag: 'UTF-8'.
23:12:33.328 [main] DEBUG com.gargoylesoftware.htmlunit.html.HtmlLink - Link node added: <link rel="icon" href="/favicon.ico"/>

23:12:33.328 [main] DEBUG com.gargoylesoftware.htmlunit.html.HtmlLink - Link type 'icon' not supported (<link rel="icon" href="/favicon.ico"/>).
23:12:33.332 [main] DEBUG com.gargoylesoftware.htmlunit.html.ScriptElementSupport - Script node added: <script type="module" lang="javascript" crossorigin="" src="/assets/index-DszroY3Z.js">
</script>

23:12:33.333 [main] DEBUG com.gargoylesoftware.htmlunit.html.ScriptElementSupport - Script is not JavaScript (type: 'module', language: ''). Skipping execution.
23:12:33.333 [main] DEBUG com.gargoylesoftware.htmlunit.html.HtmlLink - Link node added: <link rel="stylesheet" crossorigin="" href="/assets/index-C91cWaEe.css"/>

23:12:33.335 [main] DEBUG com.gargoylesoftware.htmlunit.WebClient - Load response for GET http://127.0.0.1:4173/assets/index-C91cWaEe.css
xuxiaowei-com-cn commented 3 months ago
        <dependency>
            <groupId>net.sourceforge.htmlunit</groupId>
            <artifactId>htmlunit</artifactId>
            <version>2.60.0</version>
            <scope>test</scope>
        </dependency>
package cloud.xuxiaowei.passport.oauth;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@Slf4j
class AuthorizationCodeTests {

    @Test
    void start() throws IOException {
        try (WebClient webClient = new WebClient();) {
            webClient.getOptions().setJavaScriptEnabled(true);
            webClient.getOptions().setUseInsecureSSL(true);
            HtmlPage page = webClient.getPage("https://xxw.ac.cn");
            DomNode input = page.querySelector("input");
            assertNotNull(input);
        }
    }

}
xuxiaowei-com-cn commented 3 months ago
        <dependency>
            <groupId>org.htmlunit</groupId>
            <artifactId>htmlunit</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>
package cloud.xuxiaowei.passport.oauth;

import lombok.extern.slf4j.Slf4j;
import org.htmlunit.WebClient;
import org.htmlunit.html.DomNode;
import org.htmlunit.html.HtmlPage;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@Slf4j
class AuthorizationCodeTests {

    @Test
    void start() throws IOException {
        try (WebClient webClient = new WebClient();) {
            webClient.getOptions().setJavaScriptEnabled(true);
            webClient.getOptions().setUseInsecureSSL(true);
            HtmlPage page = webClient.getPage("https://xxw.ac.cn");
            DomNode input = page.querySelector("input");
            assertNotNull(input);
        }
    }

}