Why getting “TypeError: redeclaration of const e.” while scraping with HtmlUnit?

Tags: , ,



I want to scrape live Bitcoin price using the HtmlUnit. I am running the following code to get the content of the website but getting an error.

private void htmlUnit() {

    String START_URL = "https://www.tradingview.com/symbols/BTCUSDT/?exchange=BINANCE";
    try {
        WebClient webClient = new WebClient(BrowserVersion.CHROME);
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setCssEnabled(false);
        webClient.waitForBackgroundJavaScript(10000);
        HtmlPage page = webClient.getPage(START_URL);
        System.out.println();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

Exception that I get:

      com.gargoylesoftware.htmlunit.ScriptException: TypeError: redeclaration of const e. (https://www.tradingview.com/static/bundles/category.1bca33621fc200171fb7.js#145)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:883) [htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617) [htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534) [htmlunit-core-js-2.36.0.jar:na]
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:714) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:680) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:103) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1102) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:982) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:362) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:236) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:257) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:792) [htmlunit-2.36.0.jar:2.36.0]
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) [xercesImpl-2.12.0.jar:na]
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:748) [htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1175) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1115) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:219) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:303) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3146) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2074) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:922) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:438) [neko-htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:389) [neko-htmlunit-2.36.0.jar:2.36.0]
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) [xercesImpl-2.12.0.jar:na]
    at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:991) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:246) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:190) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:269) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:160) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:534) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:317) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:469) [htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:450) [htmlunit-2.36.0.jar:2.36.0]
    at simplespringbootapp.demo.DemoApplication.htmlUnit(DemoApplication.java:64) [classes/:na]
    at simplespringbootapp.demo.DemoApplication.run(DemoApplication.java:47) [classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:779) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
    at simplespringbootapp.demo.DemoApplication.main(DemoApplication.java:37) [classes/:na]
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: TypeError: redeclaration of const e. (https://www.tradingview.com/static/bundles/category.1bca33621fc200171fb7.js#145)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$HtmlUnitErrorReporter.error(HtmlUnitContextFactory.java:420) ~[htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:259) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:235) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.defineSymbol(Parser.java:2273) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.variables(Parser.java:2172) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1225) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statements(Parser.java:1090) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.block(Parser.java:1994) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1249) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.getNextStatementAfterInlineComments(Parser.java:1496) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.forLoop(Parser.java:1607) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1198) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statements(Parser.java:1090) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.block(Parser.java:1994) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1249) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.getNextStatementAfterInlineComments(Parser.java:1496) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.ifStatement(Parser.java:1327) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1186) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parseFunctionBody(Parser.java:772) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.function(Parser.java:942) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3119) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2751) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2366) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:2322) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.nameOrLabel(Parser.java:2071) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1271) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parseFunctionBody(Parser.java:772) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.function(Parser.java:942) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3119) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2751) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.plainProperty(Parser.java:3715) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.objectLiteral(Parser.java:3615) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3127) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2751) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.arrayLiteral(Parser.java:3318) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3123) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2751) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.argumentList(Parser.java:2718) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExprTail(Parser.java:2868) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2787) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2645) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2566) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2550) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2531) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2506) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2478) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2467) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2456) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.bitOrExpr(Parser.java:2445) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.andExpr(Parser.java:2434) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.orExpr(Parser.java:2423) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.condExpr(Parser.java:2387) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.assignExpr(Parser.java:2343) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.expr(Parser.java:2322) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statementHelper(Parser.java:1281) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.statement(Parser.java:1135) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:672) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Parser.parse(Parser.java:593) ~[htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Context.parse(Context.java:2642) [htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileImpl(Context.java:2588) [htmlunit-core-js-2.36.0.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1582) [htmlunit-core-js-2.36.0.jar:na]
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$TimeoutContext.compileString(HtmlUnitContextFactory.java:222) ~[htmlunit-2.36.0.jar:2.36.0]
    at net.sourceforge.htmlunit.corejs.javascript.Context.compileString(Context.java:1571) [htmlunit-core-js-2.36.0.jar:na]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$1.doRun(JavaScriptEngine.java:705) ~[htmlunit-2.36.0.jar:2.36.0]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:868) [htmlunit-2.36.0.jar:2.36.0]
    ... 42 common frames omitted

Answer

You got this error more or less because the js engine used by HtmlUnit is not 100% compatible with the js of current browsers. The engine gets improved from version to version but there is still a lot to do.

Or more technical – have a look at this js file https://www.tradingview.com/static/bundles/category.1bca33621fc200171fb7.js. Somewhere in this code is the reason for the error….

You can set

webClient.getOptions().setThrowExceptionOnScriptError(false);

to let the js engine ignore the error and process the js code further.

And one last point

webClient.waitForBackgroundJavaScript(10000);

is not an option. You have to call this after the page retrieval.

Your code should look like this

String url = "https://www.tradingview.com/symbols/BTCUSDT/?exchange=BINANCE";
try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX)) {
    webClient.getOptions().setThrowExceptionOnScriptError(false);

    HtmlPage page = webClient.getPage(url);
    webClient.waitForBackgroundJavaScript(20_000);

    System.out.println(" ---- ");
    System.out.println(page.asText());
    System.out.println(" ---- ");
}

Hope this helps. And please keep in mind at least the chart is rendered based on a canvas – means you can get this with asText().



Source: stackoverflow