# puppetbox

> Capture screenshots of HTML using Chrome's headless mode.

Latest version **0.1.0** (published 2021-02-04) · GPL-3.0-only license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install puppetbox
pnpm add puppetbox
yarn add puppetbox
bun add puppetbox
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-02-04 |
| First published | 2021-02-03 |
| Weekly downloads | 0 |
| License | GPL-3.0-only |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14.15.4 |
| Dependencies | 2 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tim Daubenschütz |
| Maintainers | timdaub |
| Keywords | chrome, chromium, screenshot, html, headless |

## Links

- npm: https://www.npmjs.com/package/puppetbox
- npm.io page: https://npm.io/package/puppetbox

## Dependencies (2)

- [capture-chrome](https://npm.io/package/capture-chrome.md) 3.0.1
- [expressively-mocked-fetch](https://npm.io/package/expressively-mocked-fetch.md) 0.2.2

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2021-02-04
- 0.0.1 — 2021-02-03

## README

# puppetbox

![Node.js CI](https://github.com/TimDaub/puppetbox/workflows/Node.js%20CI/badge.svg)

> Capture screenshots of HTML using Chrome's headless mode.

## Requirements

- for node version, see [package.json](./package.json)

## Why puppetbox?

- Its [code base](https://raw.github.com/TimDaub/puppetbox/main/src) is tiny and maintainable.
- It's framework-agnostic. All that is needed to get started is a HTML string.

## Installation

```bash
$ npm i -D puppetbox
```

## Usage

puppetbox allows you to capture screenshots using headless Chrome by entering a
HTML string. For visual regression testing, a screenshot could later be
compared using [`looks-same`](https://github.com/gemini-testing/looks-same).

```js
import { capture, htmlEnvelope } from "puppetbox";
import { writeFileSync } from "fs";

(async () => {
  const input = htmlEnvelope("<p>hello world</p>");

  const screenshot = await capture(input, {
    height: 100,
    width: 100
  });
  writeFileSync(`example.png`, screenshot)
})();
```

screenshot of "example.png" below:

![example.png](./example.png)

### Notes

- Headless Chrome renders an HTML string that is a valid and [minimal HTML
  document](https://github.com/TimDaub/mynimal-html5-boilerplate#%CE%BCnimal-html5-boilerplate)
  differently than passing in an HTML fragment. Compare ["hello world" as an
  HTML fragment](./assets/without_html_env.png) and ["hello world" embedded
  into a valid HTML document](./assets/with_html_env.png). We recommend consistant usage of
  embedding or using fragments. A utility function for embedding a HTML fragment into
  a minimal HTML boilerplate is provided with the `htmlEnvelope` function.

## Changelog

### 0.1.0

Stop embedding fragments in HTML doc. 

- Stop exporting `capture` as default
- Export `htmlEnvelope` function
- Add tests for `capture` and `htmlEnvelope` functions
- Add Note about how headless Chrome renders fragments differently from
  documents

### 0.0.1

- Release initial version

## License

See [License](./LICENSE).

---
_Source: https://npm.io/package/puppetbox · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
