Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including node-phantom-ws with all npm packages installed. Try it out:

var nodePhantomWs = require("node-phantom-ws")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

node-phantom-ws v1.0.10

bridge between node.js and PhantomJS using pure WebSockets


This is a bridge between PhantomJs and Node.js.

This is a port of the node-phantom library to use pure WebSockets. It has the following advantages over node-phantom:

  • Fewer dependencies/layers.
  • No <script> downloads in the client - just uses the WebSocket() API.
  • Doesn't rely on the onAlert hook for callbacks - uses the onCallback mechanism.
  • Doesn't use the unreliable and huge
  • Works under cluster (node-phantom does not due to how server.listen(0) works in cluster)


You will need to install PhantomJS first. The bridge assumes that the "phantomjs" binary is available in the PATH.

For running the tests you will need Expresso. The tests require PhantomJS 1.6 or newer to pass.


npm install node-phantom


You can use it exactly like you would use Node-Phantom, for example this is an adaptation of a web scraping example :

var phantom=require('node-phantom');
phantom.create(function(err,ph) {
  return ph.createPage(function(err,page) {
    return"", function(err,status) {
      console.log("opened site? ", status);
      page.includeJs('', function(err) {
        //jQuery Loaded.
        //Wait for a bit for AJAX content to load on the page. Here, we are waiting 5 seconds.
        setTimeout(function() {
          return page.evaluate(function() {
            //Get what you want from the page using jQuery. A good way is to populate an object with all the jQuery commands that you need and then return the object.
            var h2Arr = [],
            pArr = [];
            $('h2').each(function() {
            $('p').each(function() {

            return {
              h2: h2Arr,
              p: pArr
          }, function(err,result) {
        }, 5000);


options is an optional object with options for how to start PhantomJS. options.parameters is an array of parameters that will be passed to PhantomJS on the commandline. For example


will start phantom as:

phantomjs --ignore-ssl-errors=yes

You may also pass in a custom path if you need to select a specific instance of PhantomJS or it is not present in PATH environment. This can for example be used together with the PhantomJS package like so:


You can also have a look at the test folder to see some examples of using the API.


Made by Matt Sergeant for Hubdoc Inc.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free