Node-phantom
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 socket.io.
- Works under
cluster
(node-phantom does not due to howserver.listen(0)
works in cluster)
Requirements
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.
Installing
npm install node-phantom
Usage
You can use it exactly like you would use Node-Phantom, for example this is an adaptation of a web scraping example :
var phantom=;phantom;
phantom.create(callback,options)
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
phantom
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:
phantom
You can also have a look at the test folder to see some examples of using the API.
Other
Made by Matt Sergeant for Hubdoc Inc.