HTMLUnit with WebSocket support
This is a (temporary) fork of HTMLUnit with the purpose of adding WebSocket support. The fork is an import of revision 6270 of https://htmlunit.svn.sourceforge.net/svnroot/htmlunit/trunk/htmlunit
I didn’t use git-svn as I couldn’t get it to work. This means this fork won’t be kept in sync with the official HTMLUnit in Subversion. Instead, a complete patch will be sent to the HTMLUnit project when WebSocket support is good enough.
HTMLUnit’s issue tracker has an open ticket for WebSocket support, but I’m not aware that anyone else has started working on it yet.
EDIT: I’ve been made aware of an unmerged patch by Marko Vuksanovic. It’s certainly more elaborate than this fork. You may want to apply that patch instead…
If you have comments and suggestions, please use this project’s issue tracker instead of sending me personal messages, so that other interested people can join the discussion.
The status of the API implementation is:
WebSocket(url, protocols): Not Implemented
onerror: Not Implemented
onclose: Not Implemented
readyState: Not Implemented
bufferedAmount: Not Implemented
protocol: Not Implemented
If you want to hack on this, the test you want to run is
make mvn install:install-file -DgroupId=webbit -DartifactId=webbit -Dversion=0.0.1 -Dpackaging=jar -Dfile=build/webbit.jar
If you want to build htmlunit without running all of the tests (very slow):
mvn clean install -Dmaven.test.skip=true
When you have done this once, tack on
-o to put maven offline and make it faster.
HTMLUnit uses Apache HTTP Components elsewhere in the code, but since it doesn’t implement the WebSocket protocol I couldn’t use that. I also looked at Ning Async Http Client, but it doesn’t implement WebSocket either.
I therefore went with Adam MacBeth’s WebSocket Client, which now lives in
I may switch to https://github.com/TooTallNate/Java-WebSocket or any other library that implements the protocol more faithfully later.
- Find a way to close al websockets if the page doesn’t do it itself.
I haven’t found a way to work around this, so contributions are welcome.