O'Reilly logo

PhantomJS Cookbook by Rob Friesel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with WebSockets in PhantomJS

This recipe discusses how to open and work with a WebSocket connection in PhantomJS.

Getting ready

To run this recipe, we will need a script that requests a host that also exposes WebSocket connections.

Note

Although PhantomJS version 1.9 does have WebSocket support, that support is limited to the hixie-76 draft of the protocol. PhantomJS 2.0 is scheduled to include the more modern RFC 6455 version of WebSockets. When writing scripts for PhantomJS that intend to use WebSocket connections, we must ensure that the server supports the hixie-76 version of the protocol.

Tip

A good introduction to the WebSocket protocol and the HTML5 API can be found at http://www.websocket.org/aboutwebsocket.html.

The script in this recipe ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required