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

webgets

v0.1.3

Published

Automated screenshots for your docs

Downloads

6

Readme

Webget

Webget is a command line tool for creating and updating screenshots using browser automation.

Images are defined in JSON next to where the image will be generated, ie:

./images/screenshot.png <- the generated image
./images/screenshot.png.json <- the JSON configuration file

The JSON configuration file adheres to a schema, and looks like this:

{
  "$schema": "https://usewebget.com/schema/v1.json",
  "url": "https://usewebget.com",
  "actions": [
    {
      "type": "crop",
      "width": 500,
      "height": 500
    }
  ]
}

Installation

npm install webgets

Usage

To re-generate all your screenshots, run:

npx webget update

You can filter which images are generated by specifying part of the matching image paths. For example, to update all images in the images directory, run:

npx webget update --filter images

Some update options:

--headed - Run the browser in headed mode (visible) --workers - The number of images to generate in parallel --diff - Only update images that have changed (SSIM < 99%)

Server

Webget runs a background process to avoid the cost of starting a browser everytime you want to generate an image. This server is started automatically. To stop it, run:

npx webget stop

To run the server "in process" (to see it's output), run:

npx webget server

Config

Webget can be customised using a webget.config.ts file in the root of your project. Here is an example configuration:

import type { WebgetConfig } from "./src/types";

const config: WebgetConfig = {
  async setup(asset) {
    return {
      baseUrl: "https://usewebget.com",
      ...asset,
    };
  },
};

export default config;

The setup hook is called before each image is generated, and allows you to modify the asset configuration. This is useful for setting a base URL for all your images or adding authentication cookies to the browser session.

Asset Definition

Top level properties:

{
  // the url to open in the browser
  "url": "https://usewebget.com",

  // the number of screen pixels per html pixel
  "deviceScaleFactor": 2,

  // a relative "url" will use this as a base url
  "baseUrl": "https://usewebget.com",

  // the width and height of the browser, defaults to 1280x720
  "width": 1280,
  "height": 720,

  // the quality of generated JPG images
  "quality": 80,

  // browser preferences
  "reducedMotion": "reduce",
  "colorScheme": "dark",
  "forcedColors": "active",
}

Storage state allows you to set cookies and local storage before the page is loaded. This is useful for setting authentication tokens or other state that is required for the page to render correctly:

{
  "storageState": {
    "cookies": [
      {
        "name": "session",
        "value": "secrets",
        "domain": "usewebget.com",
        "path": "/",
        "expires": -1,
        "httpOnly": true,
        "secure": true,
        "sameSite": "Lax",
      },
    ],
    "origins": [
      {
        "origin": "https://usewebget.com",
        "localStorage": [
          {
            "name": "token",
            "value": "1234",
          },
        ],
      },
    ],
  },
}

Actions are a list of operations to perform in the browser after the "url" loads:

{
  "actions": [
    {
      // click an element
      "type": "click",
      "selector": "button",
    },
    {
      // hover an element
      "type": "hover",
      "selector": "button",
    },
    {
      // scroll an element into view
      "type": "scroll",
      "selector": "button",
    },
    {
      // wait for milliseconds
      "type": "wait",
      "milliseconds": 500,
    },
    {
      // enter text into an element
      "type": "fill",
      "selector": "input",
      "text": "Hello world",
    },
    {
      // crop the final image
      "type": "crop",
      // optional element to use as the viewbox.
      // if not provided, the entire viewport is used
      "selector": "header",
      // the x / y offset of the crop, relative to viewbox of "selector" if provided
      // if <= 1 then it is a percentage of the viewbox
      "x": 0,
      "y": 0,
      // the width and height of the crop
      // if <= 1 then it is a percentage of the viewbox
      "width": 100,
      "height": 200,
      // padding around the crop
      "padding": 10,
      // ensures that any scrollable content is included in the crop
      "fullPage": true,
    },
  ],
}

Templates are experimental right now. They allow you to define an HTML template that your screenshot is loaded into. There are some examples in tests.