Phantomjs snippet take page screenshot

"use strict";
var page = require('webpage').create(),
	system = require('system'),
	server = 'https://domain.com/login.php',
    data = 'username=myusername&password=password',
    screenshot_url = 'https://domain.com/dashboard.php',
    screenshot = '/Users/myuser/screenshot.png';

page.open(server, 'post', data, function (status) {
	if (status !== 'success') {
        console.log('Unable to post!');
    } else {
    	page.viewportSize = { width: 600, height: 600 };
    	page.open(screenshot_url, function(status) {
    		if (status !== 'success') {
                console.log('Unable to load the address!');
                phantom.exit(1);
            } else {
                window.setTimeout(function () {
                    page.render(screenshot);
                    phantom.exit();
                }, 200);
            }
    	});
    }
    phantom.exit();
} 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.