静默htmlunit中的Javascript堆栈跟踪



我已将程序配置为继续处理JavaScript异常:

WebClient webClient = new WebClient(BrowserVersion.FIREFOX_ESR);
webClient.getOptions().setThrowExceptionOnScriptError(false);      // #1
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setPrintContentOnFailingStatusCode(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());

结果是,即使遇到JavaScript错误,程序也会继续运行,正如基于上述设置#1所预期的那样。

问题是错误仍在记录中。例如:

com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "jQuery" is not defined.

然后是我不关心的一百多行堆栈跟踪。

我想WebClientOptions中可能有一个public void setPrintContentOnScriptError(Boolean enabled)方法,但我没有发现。

运行htmlunit时,如何防止JavaScript堆栈跟踪扰乱输出?

您必须自定义日志配置。请看一下https://htmlunit.sourceforge.io/logging.html.

最新更新