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

screenshots-cli

v1.0.0

Published

Take screenshots for a list of URLs and viewports

Downloads

1

Readme

Screenshots

Use puppeteer to take screenshots of a list of URLs for multiple viewports

Installation

yarn add --global screenshots-cli

CLI Usage


  Take screenshots for a list of URLs and viewports

  Usage
    $ screenshots

  Options
    --version          Output version
    --urls             List of comma-separated URLs to visit. (Must include protocol)
    --viewports        List of comma-separated viewport dimensions to take screenshots.
                          Specify both width and height like: 1440x768,768x768
                          OR only specify the width to capture the entire page.
                          You can use a combination of both.

    --outputDir, -o    Screenshots directory name. Defaults to $pwd/screenshots
    --emptyDir, -rm    Empty the output directory

  Authentication Options
    --loginUrl         URL to authenticate with username/password
    --username, -u     Auth username
    --password, -p     Auth password

  Examples
    $ screenshots \
        --urls=https://mysite.com \
        --viewports=1440x768,768,480,320

Programmatic Usage

const path = require('path')
const screenshots = require('screenshots-cli')

screenshots({
  urls: ['https://mysite.com/login'],
  viewports: [
    [1440, 768], // [width, height] - height is optional
  ],
  outputDir: path.join(process.cwd(), 'screenshots'), // default
})
  .then()
  .catch()

Usage with auth

const path = require('path')
const screenshots = require('screenshots-cli')

screenshots({
  urls: ['https://mysite.com'],
  loginUrl: 'https://mysite.com/login',
  username: process.env.USERNAME,
  password: process.env.PASSWORD,
})
  .then()
  .catch()

Customising login form selectors

const path = require('path')
const screenshots = require('screenshots-cli')

screenshots({
  urls: ['https://mysite.com/myaccount'],
  loginUrl: 'https://mysite.com/login',
  username: process.env.USERNAME,
  password: process.env.PASSWORD,
  selectors: {
    username: 'input[type="username"]',
    password: 'input[type="password"]',
    submit: 'input[type="submit"]',
  },
})
  .then(results => {
    // Returns array of screenshot objects
    // See below for results type definition
  })
  .catch()

Results schema

[
  {
    filename: String,
    createdAt: Date,
    uri: Base64
  },
  ...
]

Options

| Option | Type | Required | Default | Description | | --------- | --------- | -------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------- | | urls | Array | Yes | | Array of URLs to visit | | viewports | Array | | [[1440], [768], [425], [320]] | Viewport dimensions to take for each URL | | outputDir | String | | path.join(process.cwd(), 'screenshots') | Directory to write screenshots | | emptyDir | Boolean | | false | Empty the output directory | | loginUrl | String | | | URL to authenticate | | username | String | | | Auth username | | password | String | | | Auth password | | selectors | Object | | { username: 'input[type="email"]', password: 'input[type="password"]', submit: 'form button' } | HTMLElement selectors for login form |

Running locally

Unauthenticated routes

yarn start --urls=https://mysite.com

Authenticated routes

You will be prompted for your username and password. The password will be hidden

yarn start:auth --urls=https://mysite.com/myaccount

Diffing two images

Make sure you have imagemagick installed locally:

brew install imagemagick

Compare images:

compare screenshots/one.png screenshots/two.png [-highlight-color blue] -compose src diff.png