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

@invertase/puppeteer-pool

v0.0.2

Published

Pool Puppeteer browser instances for fast access.

Downloads

153

Readme


Puppeteer browser instance pooling via generic-pool

Installation

# NPM:
npm i @invertase/puppeteer-pool
# YARN:
yarn add @invertase/puppeteer-pool

Usage

Import

const createPuppeteerPool = require('@invertase/puppeteer-pool');

Create a pool

const pool = createPuppeteerPool({
  min: 2,
  max: 10,
  puppeteerLaunchArgs: [{ headless: false }],
});

Options

  • validate: A function to validate an instance prior to use, must return a promise that resolves true or false
  • puppeteerLaunchArgs: Array of arguments to pass to puppeteer.launch when instances are created

Options provided by generic-pool:

  • max: maximum number of resources to create at any given time. (default=1)
  • min: minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently set the min to equal max. (default=0)
  • maxWaitingClients: maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future cycle of the event loop.
  • testOnBorrow: boolean: should the pool validate resources before giving them to clients.
  • acquireTimeoutMillis: max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.
  • fifo : if true the oldest resources will be first to be allocated. If false the most recently released resources will be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean, (default true)
  • priorityRange: int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources are available.
  • autostart: boolean, should the pool start creating resources, initialize the evictor, etc once the constructor is called. If false, the pool can be started by calling pool.start, otherwise the first call to acquire will start the pool. (default true)
  • evictionRunIntervalMillis: How often to run eviction checks. Default: 0 (does not run).
  • numTestsPerEvictionRun: Number of resources to check each eviction run. Default: 3.
  • softIdleTimeoutMillis: amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor (if any), with the extra condition that at least "min idle" object instances remain in the pool. Default -1 (nothing can get evicted)
  • idleTimeoutMillis: the minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due to idle time. Supersedes softIdleTimeoutMillis Default: 30000
  • Promise: Promise lib, a Promises/A+ implementation that the pool should use. Defaults to whatever global.Promise is (usually native promises).

Acquire a browser instance

const browserInstance = await pool.acquire();

Release a browser instance

const browserInstance = await pool.acquire();
// do something with your instance,
// when you're finished with the instance; call release:
await pool.release(browserInstance);

Drain and clear the pool

await pool.drain();
await pool.clear();

License

See LICENSE