Takes screeshot of a given page. This module correctly handles pages which dynamically load content making AJAX requests. Instead of waiting fixed amount of time before rendering, we give a short time for the page to make additional requests.
Example usage
var screenshot = require('url-to-image');
screenshot('http://google.com', 'google.png').fail(function(err) {
console.error(err);
}).done(function() {
// now google.png exists and contains screenshot of google.com
});
npm install url-to-image
You need to have PhantomJS installed globally. phantomjs
executable also needs to be in your PATH.
var screenshot = require('url-to-image');
This will run a PhantomJS script(url-to-image.js) which renders given url to an image.
Parameters
-
url
Url of the page which will be rendered as image. For examplehttp://google.com
. -
filePath
File path where to save rendered image. -
options
Options for page rendering.Default values for options
{ // User agent width width: 1200, // User agent height height: 800 }
Returns
Q promise object. In case of error, stderr is passed as a string to fail handler.
Detailed example
var screenshot = require('url-to-image');
var options = {
width: 600,
height: 800
}
var promise = screenshot('http://google.com', 'google.png', options);
promise.fail(function(stderr) {
console.error(stderr);
}).done(function() {
// do stuff with google.png
});
grunt test
You need to have mocha installed globally with npm install -g mocha
.
-
Commit all changes
-
Run
grunt release
, which will create new tag and publish code to GitHubTravis will release newest tag to NPM
-
Edit GitHub release notes
To see an example how to release minor/major, check https://github.com/geddski/grunt-release
This module was inspired by