StackOverflow forced me to shorten the actual exception text. The full exception is:
HtmlUnit: Attempted to refresh a page using an ImmediateRefreshHandler which could have caused an OutOfMemoryError Please use WaitingRefreshHandler or ThreadedRefreshHandler instead.
This is a tricky solution to find, so I’m posting it here.
Simply create your own empty RefreshHandler:
Then attach it to your web client:
Note that I did this in Groovy, so you might have to tweak the syntax for Java.