Skip to content
Capture screenshots using PhantomJS
Branch: master
Clone or download
Latest commit 42ce6b6 Jun 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
script add cookies option Sep 25, 2017
.gitignore
.travis.yml travis: drop unneccessary xvfb Sep 15, 2017
README.md docs(readme): add Greenkeeper badge Aug 10, 2018
example-unclipped.js initial commit Sep 15, 2017
example-unclipped.png initial commit Sep 15, 2017
example.js
example.png add cookies option Sep 25, 2017
index.js fix name of `wait` option Oct 30, 2017
package-lock.json 1.4.5 Jun 5, 2019
package.json 1.4.5 Jun 5, 2019
test.js initial commit Sep 15, 2017

README.md

capture-phantomjs

Capture screenshots using phantomjs.

build status Greenkeeper badge

Example

Capture a 1024x768 screenshot of twitter.com:

const capture = require('capture-phantomjs')
const fs = require('fs')

capture({
  url: 'https://twitter.com/',
  width: 1024,
  height: 768
}).then(screenshot => {
  fs.writeFileSync(`${__dirname}/example.png`, screenshot)
  console.log('open example.png')
})

github.com

API

screenshot({ url, width = 1024, height = 768, wait = 0, format = 'png', clip = true, cookies = [], ignoreSSLErrors = false, SSLCertificatesPath, SSLProtocol })

Capture a screenshot of url, returns a Promise which resolves with a buffer.

Options:

  • url Page url
  • width Viewport width
  • height Viewport height
  • wait Time in ms to wait after the page finished loading all initial resources
  • format File format (png, jpg, gif)
  • clip Cut the image to exact dimensions, removing the fold
  • cookies Array of cookie objects, see below
  • ignoreSSLErrors ignore SSL errors
  • SSLCertificatesPath path for PhantomJS to look for SSL certificates
  • SSLProtocol Supported protocols: sslv3, sslv2, tlsv1, any

Cookie format

The cookie format is this:

{
  name : 'valid-cookie-name',             // required
  value : 'valid-cookie-value',           // required
  domain : 'the-domain.com',              // required
  path : '/',
  httponly : true,
  secure : false,
  expires : (new Date()).getTime() + 3600 // expires in 1 hour
}

Installation

With npm do:

npm install capture-phantomjs

This project requires nodejs@8.0.0 or later.

CI

This project will work in CI environments like Travis and AppVeyor without any additional configuration. It fetches phantomjs itself and doesn't need a X server to run.

Related projects

License

(MIT)

Copyright (c) 2017 Julian Gruber <julian@juliangruber.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can’t perform that action at this time.