## nokap

**nokap** captures screenshots and PDFs from web pages (or local HTML) using headless Chrome via the [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/). It doesn't need Selenium or Playwright. Its only runtime dependencies are `websockets` and `click`.

### Install and Go

Get **nokap** from PyPI and start capturing screenshots immediately:

``` bash
pip install nokap
```

nokap finds the Chrome or Chromium already on your system. If there isn't one, or you're working inside a sandbox where full Chrome can't start, run `nokap install-chrome` to download Chrome's standalone headless build (see [Installation](user-guide/installation.md)).

Then in Python:

``` python
import nokap

# Screenshot a URL
nokap.webshot("https://example.com", "example.png")

# From HTML string (useful for table libraries)
html = "<h1>Hello, world!</h1>"
nokap.from_html(html, "hello.png")
```

Or from the command line:

``` bash
nokap webshot https://example.com screenshot.png
nokap from-html report.html report.png --selector "table" --zoom 2
```

### Why nokap?

|  |  |
|----|----|
| **Zero heavyweight deps** | No Selenium, no Playwright: just `websockets`, `click`, and Chrome |
| **Screenshots** | PNG, JPEG, WebP via CDP `Page.captureScreenshot` |
| **PDF generation** | Configurable page size, margins, orientation |
| **CSS selectors** | Capture specific elements or unions of multiple selectors |
| **Retina quality** | Zoom/scale for 2× or 3× resolution images |
| **CLI included** | `nokap webshot` and `nokap from-html` commands |
| **Jupyter safe** | Works in notebooks without event loop conflicts |
| **Sandbox friendly** | Runs in macOS agent sandboxes with `chrome-headless-shell` |

### Configuration

| Environment Variable | Purpose                                          |
|----------------------|--------------------------------------------------|
| `CHROME_PATH`        | Override Chrome binary location                  |
| `NOKAP_CHROME_ARGS`  | Extra Chrome command-line flags for every launch |
| `NOKAP_CACHE_DIR`    | Where `nokap install-chrome` stores browsers     |

### Requirements

- Python ≥ 3.10
- Chrome or Chromium installed on the system, or `chrome-headless-shell` installed with `nokap install-chrome`

### License

MIT
