> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.chaser.sh/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.chaser.sh/_mcp/server.

# Puppeteer

Connect to Chaser sessions with Puppeteer. The API is the same as connecting to a local browser — only the endpoint changes.

## Installation

```bash
npm i puppeteer-core
```

Use `puppeteer-core`, not `puppeteer`. The full `puppeteer` package downloads its own Chromium, which you don't need — the browser is on Chaser's side.

## Basic connection

```javascript
import puppeteer from "puppeteer-core";

// 1. Create a session
const { cdp_url, id } = await fetch(
  "https://api.chaser.sh/v1/sessions",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.CHASER_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ ttl_seconds: 1800 }),
  }
).then((r) => r.json());

// 2. Connect
const browser = await puppeteer.connect({ browserWSEndpoint: cdp_url });
const [page] = await browser.pages();

// 3. Automate
await page.goto("https://www.cloudflare.com");
console.log(await page.title());

// 4. Screenshot via the API
const png = await fetch(
  `https://api.chaser.sh/v1/sessions/${id}/screenshot`,
  {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.CHASER_KEY}` },
  }
).then((r) => r.arrayBuffer());
writeFileSync("page.png", Buffer.from(png));

// 5. Clean up
await fetch(`https://api.chaser.sh/v1/sessions/${id}`, { method: "DELETE" });
```

## Notes

- Use `browserWSEndpoint`, not `browserURL` (which is deprecated).
- `puppeteer.connect()` returns immediately. The session must be in `ready` status first.
- As with patchright: don't create new contexts, don't override the user-agent, and use the `/screenshot` endpoint instead of `page.screenshot()`.
- Puppeteer's bundled Chromium has known automation artifacts. For production use, prefer [patchright](../playwright.md) (Playwright-based) which patches these at the browser level.