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

snapage

v1.3.2

Published

take beautiful page screenshots

Downloads

2

Readme

snapage

snap a page !

snapage allows to create high quality web page screenshots/pdfs, for multiple viewports concurrently, with custom styles, element screeenshots, scripts and more!

install

npm install snapage

usage

const snap = require('snapage');
(async () => {
  await snap('https://apple.com', {
    name: 'iPad Pro',
    fullPage: true,
    scroll: true,
    viewports: ['iPad Pro'],
    style: {
      filter: 'grayscale(100%)'
    }
  });
})();

features

✅ plug and play
✅ element & full page screenshots
✅ custom css styles
✅ custom script to run before snap
✅ supports pdf
✅ supports all chrome emulated devices and their orientation
✅ supports lazy loaded content by scrolling the page
✅ uses puppeteer-cluster for concurrenct screenshots

api

export type Style = Record<string, string>;

// for string viewport, snapage will emulate the given device (e.g 'Nexus 4 landscape')
// see pptr devices: https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts
export type Viewport = string | {
  width?: number;
  height?: number;
}


export type SnapOptions = {
  name?: string;
  path?: string;
  viewports?: Viewport[];
  style?: Style;
  script?: string;
  fullPage?: boolean;
  scroll?: boolean;
  persist?: boolean;
  printBackground?: boolean;
  mode?: string;
  wait?: number;
};

export type SnapMeta = {
  name: string;
  snapPath: string;
  snapDir: string;
  viewport: Viewport;
  device: boolean;
  opts: Record<string, any>;
};

export type SnapResult = {
  meta: SnapMeta[];
  snaps: Buffer[];
}

export default function snap(url: string, options?: SnapOptions): Promise<SnapResult>;

examples

pdf

snap a full page pdf of apple.com, in an iPhone X and desktop 800x600, scroll the page to get lazy loaded content.

const snap = require('snapage');
(async () => {
  await snap('https://apple.com', {
    mode: 'pdf', 
    scroll: true, 
    viewports: ['iPhone X', {width: 800, height: 600}]
  });
})()

custom css style

snap a viewport screenshot of apple.com, on desktop 800x600, desaturate colors by 50%.

const snap = require('snapage');
(async () => {
  await snap('https://apple.com', {
    style: {
      filter: 'saturate(50%)'
    }, 
    viewports: [{width: 800, height: 600}, '']
  });
})()

custom script

snap a viewport screenshot of npmjs.com, on desktop 1200x1080, add a red border to every element on the page via a script.

const snap = require('snapage');
(async () => {
  await snap('https://www.npmjs.com', {
    script: 'document.querySelectorAll("*").forEach(e => e.style.border = "1px solid red")',
    viewports: [{width: 1200, height: 1080}]
  });
})()

don't persist

don't persist screenshots instead return screenshot per viewport provided in the viewports array. by default, snapagesaves the screenshots/pdfs to the snapDir provided in config.

import snap, {SnapResult} from 'snapage';
const screenshots: SnapResult = await snap('https://google.com', {
    persist: false,
    viewports: ['iPad Pro', { width: 800, height: 600 }],
  });
console.log(screenshots);
// {
//   snaps: [
//     <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 08 00 00 00 0a ac 08 06 00 00 00 4b e6 13 8c 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 20 00 ... 204866 more bytes>,
//     <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 0c 80 00 00 09 60 08 06 00 00 00 4a f8 ad 5d 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 20 00 ... 638779 more bytes>
//   ],
//   meta: [
//     {
//       viewport: 'iPad Pro',
//       name: 'snap_YCT5Qt5',
//       snapPath: undefined,
//       snapDir: '/workspaces/experiments/snapage/snaps',
//       opts: [Object],
//       device: true
//     },
//     {
//       viewport: [Object],
//       name: 'snap_aW3dz0g',
//       snapPath: undefined,
//       snapDir: '/workspaces/experiments/snapage/snaps',
//       opts: [Object],
//       device: false
//     },
//   ]
// }