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

capture-all

v1.0.0

Published

Flexible utility to get screenshots from Web pages

Downloads

34

Readme

capture-all

Flexible utility to get screenshots from Web pages

Install

$ npm i capture-all
# or
$ yarn add capture-all

Example

const { captureAll } = require('capture-all')
const fs = require('fs')

captureAll([
  {
    // Web page URL which will be captured
    url: 'https://www.google.com/',

    // Selector for capturing element
    target: 'body',

    // Selectors to hide from capture (add `visibility: hidden;` to the elements)
    hidden: ['#gb'],

    // Selectors to remove from capture (add `display: none;` to the elements)
    remove: ['#fbar'],

    // Delay (milliseconds) before taking screenshot
    delay: 3000,

    // Viewport size of a browser
    viewport: {
      width: 1024,
      height: 800
    }
  }
]).then(results => {
  results.forEach((result, i) => {
    fs.writeFileSync(`result-${i}.png`, result.image)
  })
})

Hooking Capturing Processing

You can define detailed behavior of the capturing processing with capture option. The capture option is an function receving Puppeteer's Page instance as the 1st argument and a capturing function as the 2nd argument. You have to call the 2nd argument function by your hand when you specify capture option.


const { captureAll } = require('capture-all')
const fs = require('fs')

captureAll([
  {
    url: 'https://www.google.com/',
    target: 'body',
    viewport: {
      width: 1024,
      height: 800
    },

    // Define the behavior around capturing
    capture: async (page, capture) => {
      // Click a button in the page by using Puppeteer API
      const button = await page.$('#some-button')
      await button.click()

      // Capture the page at this moment
      await capture()

      // Click the button again
      await button.click()

      // Capture the page again
      await capture()
    }
  }
]).then(results => {
  results.forEach((result, i) => {
    fs.writeFileSync(`result-${i}.png`, result.image)
  })
})

API

captureAll(targets: CaptureTarget[], options?: CaptureOptions): Promise<CaptureResult[]>

Capture screenshots of Web pages which specified by targets and return an array of CaptureResult object including captured image buffer.

CaptureTarget may have the following properties:

  • url: Web page URL which will be captured (required)
  • target: a selector for capturing element
  • hidden: an array of selector to hide matched elements from captured image
  • remove: an array of selector to remove matched elements from captured image
  • disableCssAnimation: true if css animations / transitions are to be disabled. (default: true)
  • delay: Delay (milliseconds) before taking screenshot
  • viewport: viewport size of browser
  • capture: You can hook the capturing processing by using this option. See Hooking Capturing Processing for details.

CaptureOptions may have the following properties:

  • concurrency: a number of process which will be created for capture
  • puppeteer: an object passed to puppeteer.launch

CaptureResult has the following properties:

  • index: Index of capture results generated by the same CaptureTarget. The result can be more than one if you specify capture option.
  • image: captured image buffer
  • url: captured Web page URL
  • target: a selector of captured element
  • hidden: an array of selector which is hidden from captured image
  • remove: an array of selector which is removed from captured image
  • disableCssAnimation: true if css animations / transitions are to be disabled
  • delay: Delay (milliseconds) before taking screenshot
  • viewport: viewport size of browser

createCaptureStream(targets: CaptureTarget[], options?: CaptureOptions): ReadableStream<CaptureResult>

Similar to captureAll but returns readable stream of CaptureResult instead.

License

MIT