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

docketeer

v1.2.0

Published

A tiny application that lets you use a dockerised browser for Puppeteer

Downloads

12

Readme

Docketeer

Docketeer allows you to run your Puppeteer scripts on your host machine whilst launching the browser in a docker container. This is particularly useful when you need to have a consistent environment regardless of the host machine running the scripts. For example, if you are running visual snapshot tests on macOS when your build pipeline runs them in Linux.

Usage

docketeer [--exec-path=<browser_bin>] [--bind-port=<port>] <docker_image> <command>

Simply prefix your usual command with docketeer via npx, pnpx or whatever the hell Yarn's equivalent is:

npx docketeer npm test

You will also need to tweak your server to bind to host.docker.internal. An environment variable, DOCKETEER_ENABLED, is provided for easy transition in your configs. For example, this is how you might change your Storybook Storyshots puppeteer config:

  test: puppeteerTest({
    testTimeout: 600000,
    setupTimeout: 600000,
    storybookUrl: process.env.DOCKETEER_ENABLED ? "http://host.docker.internal:9003" : "http://localhost:9003",
    
    // ...
})

Options

| Option | Env | Description | Default | | :------------------------: | :-------------------------: | :-------------------------------------------------- | :-------------------------: | | <docker_image> | DOCKETEER_IMAGE | The docker image for the browser you want to launch | — | | --exec-path=<path> | DOCKETEER_EXEC_PATH | Path to the browser binary inside the docker image | google-chrome | | --docker-run-args=<args> | DOCKETEER_DOCKER_RUN_ARGS | Additional arguments to docker run | — |

Why

A lot of guides recommend two approaches when it comes to running Puppeteer via docker:

  • Use docker run to run your scripts with the local files mounted inside the docker container. For certain test runners (e.g. Karma), this may mean compilation happens inside the container and this can be slow. It also means that native modules may not work correctly, and the image has to be rebuilt every time you upgrade Node locally for new features.
  • Run something like Browserless and change your scripts to use puppeteer.attach() instead of puppeteer.launch(). This usually means changing your workflow entirely, or maintaining two separate approaches, one for local and one for your build pipeline.

With the mounting approach, here's how long it takes to run our Storybook Storyshots visual snapshot tests with a mounted volume on macOS:

$ time docker run \
	-it \
	--rm \
	--name ads \
	--workdir=/repo \
	--mount type=bind,source="$(currentDir)",target=/repo node-with-chrome-and-node-gyp:0.0.1 \
	pnpm visual-snapshot

...
________________________________________________________
Executed in   21.44 mins      fish           external
   usr time  437.04 millis    0.16 millis  436.89 millis
   sys time  483.23 millis    1.56 millis  481.67 millis

And here's how long it takes using Docketeer:

$ time npx docketeer --exec-path=chromium-browser node-with-chrome-and-node-gyp:0.0.1 pnpm visual-snapshot

...
________________________________________________________
Executed in  387.92 secs      fish           external
   usr time  556.42 millis  114.00 micros  556.31 millis
   sys time  405.67 millis  629.00 micros  405.04 millis

That's a saving of over 15 minutes!

ℹ️  Docker 4.6 has an experimental feature called virtiofs which makes large speed improvements. Using Docketeer is still significantly faster, about twice as fast in one of my tests (~140 seconds > down to ~50).

Known Issues

  • When Puppeteer is launched without supplying the userDataDir option, it generates a temp dir and changes how the browser is closed: it sends a SIGKILL instead of allowing the browser to close gracefully. With Docketeer, this kills the entire spawned process tree, including the docker run command, so the browser does not actually exit and the container is kept alive.

    To work around this, make sure you supply the userDataDir option to puppeteer.launch() when running via Docketeer:

    puppeteer.launch({
      userDataDir: process.env.DOCKETEER_ENABLED ? './' : null,
      // ...
    });

    Don't worry about the directory specified, Docketeer will remove the --user-data-dir flag supplied to Chrome.