https://github.com/epoberezkin/phantom-bluebird
Core phantom modules promisified with bluebird
https://github.com/epoberezkin/phantom-bluebird
Last synced: about 2 months ago
JSON representation
Core phantom modules promisified with bluebird
- Host: GitHub
- URL: https://github.com/epoberezkin/phantom-bluebird
- Owner: epoberezkin
- License: mit
- Created: 2015-05-02T16:20:59.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-06T00:04:14.000Z (almost 10 years ago)
- Last Synced: 2024-10-18T10:27:58.180Z (6 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# phantom-bluebird
Core phantom modules promisified with [bluebird](https://github.com/petkaantonov/bluebird/blob/master/API.md)
## Usage
```
npm install phantom-bluebird --save
```It is NOT a node module.
This module can be used in phantomjs scripts to use promise api instead of non-standard callback api of phantomjs modules.
## webpage module
Same as phantomjs [webpage module](http://phantomjs.org/api/webpage/), but method `open` is promisified.
```js
require('phantom-bluebird')();
// replaces webpage and child_process with modules from this package.
// don't call this function if you don't want core modules replaced.var webpage = require('webpage');
// or var webpage = require('phantom-bluebird/lib/webpage');
// or var webpage = require('phantom-bluebird').webpage;var page = webpage.create();
page.open('http://example.com')
.then(function (status) {
console.log('Page title:', page.title);
})
.catch(function (err) {
console.log('Can\'t open page');
})
.finally(function() {
phantom.exit();
});
```Only open method of page object is promisified at the moment.
## child_process module
Same as phantom [child_process module](http://phantomjs.org/api/child_process/), but methods are promisified.
`spawn` method supports additional options (see example below).
```js
require('phantom-bluebird')();
var spawn = require('child_process').spawn;
// or var spawn = require('phantom-bluebird/lib/child_process').spawn;spawn('node', ['--harmony', 'app'], {
log: true,
// with this option child process stdout and stderr are logged to console
startedLog: 'started'
// promise will resolve when child process logs string containing "started"
// without 'startedLog' option, promise will resolve immediately
})
.bind({})
.then(function (child) {
console.log('app started');
this.app = child;
})
.then(function () {
// ... do something, e.g. open page
})
.finally(function () {
this.app.kill();
phantom.exit();
});
```TODO: example for `execFile` method.