node-phantom-promise
A simple wrapper for baudehlo/node-phantom-simple with promise
This module is API-compatible with
node-phantom but doesn't rely on
WebSockets
/ socket.io
. In essence the communication between Node and
Phantom / Slimer has been simplified significantly. It has the following advantages
over node-phantom
:
- Fewer dependencies/layers.
- Doesn't use the unreliable and huge socket.io.
- Works under
cluster
(node-phantom does not, due to how it works)server.listen(0)
works in cluster. - Supports SlimerJS.
- Promise callback
Installing
npm install node-phantom-promise # Also need phantomjs OR slimerjs: npm install phantomjs# OR npm install slimerjs
Note. SlimerJS is not headless and requires a windowing environment.
Under Linux/FreeBSD/OSX xvfb can be used to run headlessly.. For example, if you wish
to run SlimerJS on Travis-CI, add those lines to your .travis.yml
config:
before_script: - export DISPLAY=:99.0 - "sh -e /etc/init.d/xvfb start"
Usage
Refer to Usage
in baudehlo/node-phantom-simple
** Please be aware that
-
You should use it in promise style, put callback function in
then
orcatch
-
the argument
err
is moved tocatch
of promise chain, the rest argument will be available inthen
of promise chain
Example
Highly recommended to use this with co
'use strict' const co = const driver = const phantomjs = const wait =
Or using ES7 async
/await
with babel
! { const browser = await driver const page = await browser const status = await page console await page // jQuery Loaded. // Wait for a bit for AJAX content to load on the page. Here, we are waiting 5 seconds. await const result = await page console browser}
But no one will stop you from using the old school way
'use strict' const driver = const phantomjs = driver