Created
October 1, 2016 17:05
-
-
Save davidmfoley/4efec53e538612df463e134d2fe0a797 to your computer and use it in GitHub Desktop.
take snapshot of local html page w node-phantom-simple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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