I am trying to render the HTML containing d3(d3.v6.3.1.min.js) using HtmlUnit in headless mode. I am using the latest version of HtmlUnit . Getting some issue. Please find the below details.
How can I fix it?
Here is my code :
WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED);
//webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setJavaScriptEnabled(true);
File file = new File("Path of the html");
HtmlPage page = webClient.getPage(file.toURI().toURL().toString());
String js = "var data = "+jsonSeries+";\n";
js += "drawChart(data);";
webClient.waitForBackgroundJavaScript(10000);
page.executeJavaScript(js);
svgImage = page.asXml().substring(page.asXml().indexOf("<svg"),page.asXml().indexOf("</svg>")+6);
Here is the error log :
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: syntax error (file: d3.v6.3.1.min.js#2)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory$HtmlUnitErrorReporter.error(HtmlUnitContextFactory.java:436) ~[htmlunit-2.54.0.jar:2.54.0]
at net.sourceforge.htmlunit.corejs.javascript.Parser.addError(Parser.java:251) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:330) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:321) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.reportError(Parser.java:314) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.primaryExpr(Parser.java:3114) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.memberExpr(Parser.java:2665) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.unaryExpr(Parser.java:2568) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.expExpr(Parser.java:2488) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.mulExpr(Parser.java:2471) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.addExpr(Parser.java:2457) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.shiftExpr(Parser.java:2440) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.relExpr(Parser.java:2418) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.eqExpr(Parser.java:2394) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitAndExpr(Parser.java:2385) ~[htmlunit-core-js-2.54.0.jar:?]
at net.sourceforge.htmlunit.corejs.javascript.Parser.bitXorExpr(Parser.java:2376) ~[htmlunit-core-js-2.54.0.jar:?]