npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webshot-query

v0.18.0

Published

Easy website screenshots, with url query support (mostly a hack)

Downloads

1

Readme

Build Status

node-webshot

Webshot provides a simple API for taking webpage screenshots. The module is a light wrapper around PhantomJS, which utilizes WebKit to perform the page rendering.

Examples

A simple url example:

var webshot = require('webshot');

webshot('google.com', 'google.png', function(err) {
  // screenshot now saved to google.png
});

An html example:

var webshot = require('webshot');

webshot('<html><body>Hello World</body></html>', 'hello_world.png', {siteType:'html'}, function(err) {
  // screenshot now saved to hello_world.png
});

Alternately, the screenshot can be streamed back to the caller:

var webshot = require('webshot');
var fs      = require('fs');

var renderStream = webshot('google.com');
var file = fs.createWriteStream('google.png', {encoding: 'binary'});

renderStream.on('data', function(data) {
  file.write(data.toString('binary'), 'binary');
});

An example showing how to take a screenshot of a site's mobile version:

var webshot = require('webshot');

var options = {
  screenSize: {
    width: 320
  , height: 480
  }
, shotSize: {
    width: 320
  , height: 'all'
  }
, userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)'
    + ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g'
};

webshot('flickr.com', 'flickr.jpeg', options, function(err) {
  // screenshot now saved to flickr.jpeg
});

Options

An optional options object can be passed as the parameter directly preceding the callback in a call to webshot.

PhantomJS version

By default this package installs PhantomJS 1.9.x. Several issues exist in this version that are fixed in v2, but v2 is not yet stable across all platforms. The phantomPath option can be used to get around this if you want to try a more recent PhantomJS version. See this issue: https://github.com/brenden/node-webshot/issues/100

Phantom page properties

In addition to these options, the following options can be specified and will be passed to the Phantom page object: paperSize, zoomFactor, cookies, customHeaders, and settings.

Phantom callbacks

Arbitrary scripts can be run on the page before it gets rendered by using any of Phantom's page callbacks, such as onLoadFinished or onResourceRequested. For example, the script below changes the text of every link on the page:

var options = {
  onLoadFinished: function() {
    var links = document.getElementsByTagName('a');

    for (var i=0; i<links.length; i++) {
      var link = links[i];
      link.innerHTML = 'My custom text';
    } 
  }
};

Note that the script will be serialized and then passed to Phantom as text, so all variable scope information will be lost. However, variables from the caller can be passed into the script as follows:

var options = {
  onLoadFinished: {
    fn: function() {
      var links = document.getElementsByTagName('a');

      for (var i=0; i<links.length; i++) {
        var link = links[i];
        link.innerHTML = this.foo;
      } 
    }
  , context: {foo: 'My custom text'}
  }
};

Tests

Tests are written with Mocha and can be run with npm test. The tests use node-imagemagick and thus require that the imagemagick CLI tools be installed.

Running on Heroku

See this comment.

Grunt

grunt-webshot is a Grunt wrapper for this package.

CLI

webshot-cli is a CLI interface for this package.

License

(The MIT License)

Copyright (c) 2012 Brenden Kokoszka

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.