If you don't need JavaScript support, this is the easiest way to disable it:
WebClient client = new WebClient(BrowserVersion.BEST_SUPPORTED); client.getOptions().setThrowExceptionOnFailingStatusCode(false); client.getOptions().setPrintContentOnFailingStatusCode(false); client.getOptions().setThrowExceptionOnScriptError(false); client.getOptions().setJavaScriptEnabled(false); client.setCssErrorHandler(new SilentCssErrorHandler()); client.setHTMLParserListener(new HTMLParserListener() { @Override public void error(String message, URL url, String html, int line, int column, String key) { } @Override public void warning(String message, URL url, String html, int line, int column, String key) { } });
You also disable exceptions and report error status codes, JavaScript errors, CSS errors, and HTML parsing errors.
If you need JavaScript support, you can use your own implementation for JavaScript errors:
client.setJavaScriptErrorListener(new JavaScriptErrorListener() { @Override public void timeoutError(HtmlPage arg0, long arg1, long arg2) { } @Override public void scriptException(HtmlPage arg0, ScriptException arg1) { } @Override public void malformedScriptURL(HtmlPage arg0, String arg1, MalformedURLException arg2) { } @Override public void loadScriptError(HtmlPage arg0, URL arg1, Exception arg2) { } });
If you do not need it, you can also just disable it:
client.getOptions().setCssEnabled(false);
Thus, there is no need to configure any other Logger.
Samuel Philipp Apr 12 '19 at 22:22 2019-04-12 22:22
source share