HtmlUnit Javascript Engine – Do you need it?

The Rhino engine used by HtmlUnit is great but can be slow. If you are worried about performance you can ask yourself whether you really need it. You can always enable it if you need it.

These are the settings I am currently using which is quick enough for me a the moment.


public class HtmlUnitWebClient extends WebClient {

    public HtmlUnitWebClient() {

super(BrowserVersion.CHROME);
super.setIncorrectnessListener(new IncorrectnessListenerImpl() {
@Override
public void notify(String arg0, Object arg1) {
//do nothing
}
});

final SilentCssErrorHandler eh = new SilentCssErrorHandler();
super.setCssErrorHandler(eh);
super.getOptions().setThrowExceptionOnScriptError(false);
super.getOptions().setThrowExceptionOnFailingStatusCode(false);
super.getOptions().setUseInsecureSSL(true);
       super.getOptions().setCssEnabled(false);
       super.getOptions().setPopupBlockerEnabled(false);
       super.getOptions().setRedirectEnabled(true);
      super.getOptions().setJavaScriptEnabled(false);
      super.setJavaScriptTimeout(3600);
super.getOptions().setTimeout(9000);
setCookieManager(new CookieManager() {
protected int getPort(final URL url) {
final int r = super.getPort(url);
return r != -1 ? r : 80;
}
});

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s