How to create a webpage screenshot with NodeJs and PhantomJS

To create webpage screenshots we are using PhantomJs. PhantomJS is a headless WebKit scriptable with a JavaScript API. It has very fast and native support for various web standards like DOM handling, CSS selector, JSON, Canvas, and SVG. In simple words PhantomJS is a web browser without a graphical user interface.Assuming you already downloaded and installed PhatomJS, create a JavaScript file (capturescreen.js) with the following contents.

Phantom



var wpage = require('webpage').create();

wpage.open('http://wantcode.in/', function() {
    wpage.render('wantcode.png');
    phantom.exit();
});

Then you need to run this script in browser it won't work. you need to run in command line.


phantomjs capturescreen.js

After running this see in the same folder a png file is create of screenshot.For more option you can read the phantomJs here.Please feel free to comment below for suggestions and problems.

No comments:

Post a Comment

Download the eBook of react js for beginners

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single page applications...

Popular