# --cdp

Source: https://zshot-cli.com/reference/flags/server/cdp/
Markdown: https://zshot-cli.com/reference/flags/server/cdp/index.md
Section: [Reference](https://zshot-cli.com/reference/) › [Flags](https://zshot-cli.com/reference/flags/) › [Server](https://zshot-cli.com/reference/flags/server/)
CLI: `--cdp` · REST: CLI only
Value: `HOST:PORT`
License: [Pro](https://zshot-cli.com/support/licenses/pro)

Start a server using the Chrome DevTools Protocol, so a Playwright, Puppeteer or other CDP client can control ZShot.

| Form | Behavior |
| --- | --- |
| `--cdp HOST:PORT` | Prints the endpoint, `ws://HOST:PORT/devtools/browser/<token>`, on stdout and serves until ZShot is stopped |
| `--cdp -- COMMAND` | Serves on a loopback port the system picks, runs `COMMAND` with `ZSHOT_CDP_URL` set to the endpoint, and exits with its exit code, or 127 when it cannot start |
| `--cdp HOST:PORT -- COMMAND` | As above, on `HOST:PORT` |

The endpoint's path carries a random token, and a client needs the whole URL to connect. The command receives the environment ZShot started with; Ctrl-C reaches it directly, and a SIGTERM sent to ZShot is passed on. [`--cdp-webdriver`](/reference/flags/server/cdp-webdriver) adds chromedriver's attach for WebDriver clients.

Cannot be combined with [`--server`](/reference/flags/server/server), [`--mcp-local-server`](/reference/flags/agents/mcp-local-server), a URL, `-f`, `-t` or `--navigate`. Each new browser context starts from the [storage](/reference/storage) flags given at startup.

## Warning: Window Resizing Is Poorly Supported

The browser has no window. Size a page with the client's viewport call, such as Playwright's `page.setViewportSize`, rather than by resizing its window.

## Example

Serve on port 9222:

**CLI**

```sh
zshot --cdp 127.0.0.1:9222
```

Run a Playwright script against ZShot, with `capture.mjs`:

```js
import { chromium } from "playwright-core";

const browser = await chromium.connectOverCDP(process.env.ZSHOT_CDP_URL);
const page = await browser.contexts()[0].newPage();
await page.goto("https://zshot-cli.com/example_assets/hello_zshot/");
await page.screenshot({ path: "hello.png" });
console.log(await page.title());
await browser.close();
```

**CLI**

```sh
zshot --cdp -- node capture.mjs
```

## Related

Flags:

- [`--cdp-webdriver`](https://zshot-cli.com/reference/flags/server/cdp-webdriver/)
- [`--server`](https://zshot-cli.com/reference/flags/server/server/)
- [`--storage`](https://zshot-cli.com/reference/flags/browser/storage/)
- [`--cookie`](https://zshot-cli.com/reference/flags/browser/cookie/)
- [`--navigator-captures-playwright`](https://zshot-cli.com/reference/flags/navigator/navigator-captures-playwright/)

Topics:

- [Storage](https://zshot-cli.com/reference/storage/)
- [connectOverCDP](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp) — Playwright
- [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/)

## Navigation

- [Examples](https://zshot-cli.com/examples/)
- [Download](https://zshot-cli.com/download/)
- [Purchase](https://zshot-cli.com/purchase/)
- [Reference](https://zshot-cli.com/reference/)
  - [Formats](https://zshot-cli.com/reference/formats/)
  - [Flags](https://zshot-cli.com/reference/flags/)
    - [Common](https://zshot-cli.com/reference/flags/common/)
    - [Agents](https://zshot-cli.com/reference/flags/agents/)
    - [Archive](https://zshot-cli.com/reference/flags/archive/)
    - [Browser](https://zshot-cli.com/reference/flags/browser/)
    - [Diagnostics](https://zshot-cli.com/reference/flags/diagnostics/)
    - [Document](https://zshot-cli.com/reference/flags/document/)
    - [Image](https://zshot-cli.com/reference/flags/image/)
    - [Navigator](https://zshot-cli.com/reference/flags/navigator/)
    - [Security](https://zshot-cli.com/reference/flags/security/)
    - [Server](https://zshot-cli.com/reference/flags/server/)
      - **--cdp**
      - [--cdp-webdriver](https://zshot-cli.com/reference/flags/server/cdp-webdriver/)
      - [--server](https://zshot-cli.com/reference/flags/server/server/)
      - [--server-additional-asset-expiration](https://zshot-cli.com/reference/flags/server/server-additional-asset-expiration/)
      - [--server-basic-auth](https://zshot-cli.com/reference/flags/server/server-basic-auth/)
      - [--server-bind-address](https://zshot-cli.com/reference/flags/server/server-bind-address/)
      - [--server-bind-port](https://zshot-cli.com/reference/flags/server/server-bind-port/)
      - [--server-cache](https://zshot-cli.com/reference/flags/server/server-cache/)
      - [--server-cache-size-limit](https://zshot-cli.com/reference/flags/server/server-cache-size-limit/)
      - [--server-cache-ttl](https://zshot-cli.com/reference/flags/server/server-cache-ttl/)
      - [--server-enable-mcp](https://zshot-cli.com/reference/flags/server/server-enable-mcp/)
      - [--server-enable-prometheus](https://zshot-cli.com/reference/flags/server/server-enable-prometheus/)
      - [--server-enable-schema](https://zshot-cli.com/reference/flags/server/server-enable-schema/)
      - [--server-max-concurrency](https://zshot-cli.com/reference/flags/server/server-max-concurrency/)
      - [--server-prometheus-auth](https://zshot-cli.com/reference/flags/server/server-prometheus-auth/)
      - [--server-prometheus-bind-address](https://zshot-cli.com/reference/flags/server/server-prometheus-bind-address/)
      - [--server-prometheus-bind-port](https://zshot-cli.com/reference/flags/server/server-prometheus-bind-port/)
      - [--server-queue-requests](https://zshot-cli.com/reference/flags/server/server-queue-requests/)
      - [--server-signed-url](https://zshot-cli.com/reference/flags/server/server-signed-url/)
      - [--server-signed-url-max-age](https://zshot-cli.com/reference/flags/server/server-signed-url-max-age/)
      - [--server-token-auth](https://zshot-cli.com/reference/flags/server/server-token-auth/)
      - [--server-update-adblock-interval](https://zshot-cli.com/reference/flags/server/server-update-adblock-interval/)
      - [--server-update-blocklist-interval](https://zshot-cli.com/reference/flags/server/server-update-blocklist-interval/)
    - [Video](https://zshot-cli.com/reference/flags/video/)
  - [Agents](https://zshot-cli.com/reference/agents/)
  - [Configuration](https://zshot-cli.com/reference/configuration/)
  - [Crawling](https://zshot-cli.com/reference/crawling/)
  - [Docker](https://zshot-cli.com/reference/docker/)
  - [Exit Codes](https://zshot-cli.com/reference/exit_codes/)
  - [Linux](https://zshot-cli.com/reference/linux/)
  - [LLM Connections](https://zshot-cli.com/reference/llm_connections/)
  - [LLM Formatting](https://zshot-cli.com/reference/llm_formatting/)
  - [Local Inputs](https://zshot-cli.com/reference/inputs/)
  - [Navigator](https://zshot-cli.com/reference/navigator/)
  - [Security](https://zshot-cli.com/reference/security/)
  - [Server](https://zshot-cli.com/reference/server/)
  - [Shell completions](https://zshot-cli.com/reference/shell_completions/)
  - [Storage](https://zshot-cli.com/reference/storage/)
  - [Timeouts](https://zshot-cli.com/reference/timeouts/)
  - [Web Bot Auth](https://zshot-cli.com/reference/web_bot_auth/)
- [Support](https://zshot-cli.com/support/)
- [Changelog](https://zshot-cli.com/changelog/)

Site index: https://zshot-cli.com/llms.txt

