Skip to content

Instantly share code, notes, and snippets.

@davidmfoley
Created October 1, 2016 17:05
Show Gist options
  • Select an option

  • Save davidmfoley/4efec53e538612df463e134d2fe0a797 to your computer and use it in GitHub Desktop.

Select an option

Save davidmfoley/4efec53e538612df463e134d2fe0a797 to your computer and use it in GitHub Desktop.
take snapshot of local html page w node-phantom-simple
'use strict';
var driver = require('node-phantom-simple');
var phantomPath = require('phantomjs-prebuilt').path;
// YMMV
const snapshotTimeout = 15 * 1000;
function capture(indexPath, size, snapshotPath, cb) {
driver.create({ path: phantomPath }, function (err, browser) {
if (err) return cb(err);
browser.createPage((err, page) => {
if (err) return cb(err);
page.set('viewportSize', {width: size.width, height: size.height});
page.open('file://' + indexPath, (err, status) => {
if (err) return cb(err);
setTimeout(() => {
page.render(snapshotPath, {}, cb);
}, snapshotTimeout);
});
});
});
}
module.exports = {
capture
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment