> ## Documentation Index
> Fetch the complete documentation index at: https://docs.adscrawl.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Discover CDP Endpoint

> Retrieve the Chrome DevTools Protocol discovery JSON for a session, including the pre-rewritten WebSocket debugger URL.

Retrieve the Chrome DevTools Protocol discovery JSON for a session. The response includes a `webSocketDebuggerUrl` pre-rewritten to the public, session-scoped CDP WebSocket path. Use it directly rather than constructing the URL manually.

<ParamField path="sessionId" type="string" required>
  Session ID returned by `POST /cdp/sessions` or `GET /cdp/sessions`.
</ParamField>

<ParamField query="token" type="string" required>
  The data token already embedded in the `cdpBaseUrl` returned when the session was created. Do not substitute your `x-api-key` here.
</ParamField>

## Response

<ResponseField name="Browser" type="string">
  Chrome version string, e.g. `Chrome/136.0.0.0`.
</ResponseField>

<ResponseField name="Protocol-Version" type="string">
  CDP protocol version, e.g. `1.3`.
</ResponseField>

<ResponseField name="User-Agent" type="string">
  The browser's User-Agent string.
</ResponseField>

<ResponseField name="V8-Version" type="string">
  V8 engine version.
</ResponseField>

<ResponseField name="WebKit-Version" type="string">
  WebKit version.
</ResponseField>

<ResponseField name="webSocketDebuggerUrl" type="string">
  Pre-rewritten WebSocket URL for the browser CDP endpoint. Pass this directly to your CDP client.
</ResponseField>

| Status | Meaning |
| - | - |
| `200` | Chrome discovery JSON with a rewritten `webSocketDebuggerUrl`. |
| `401` | The data token is missing or invalid. |
| `404` / `409` / `410` | The session is missing, stopping, or expired. |
| `502` | Failed to fetch upstream CDP discovery from the cloud backend. |
| `503` | The session backend is unavailable. |

## Connect over WebSocket

Upgrade to a WebSocket connection to the browser's CDP endpoint. CDP messages are proxied bidirectionally between your client and the Chromium instance running in the cloud. Use the `webSocketDebuggerUrl` returned by the discovery endpoint rather than constructing this URL manually.

<ParamField path="sessionId" type="string" required>
  Current CDP session ID.
</ParamField>

<ParamField path="browserId" type="string" required>
  Browser target ID from the discovery endpoint. Prefer copying the full `webSocketDebuggerUrl` directly instead of assembling this path yourself.
</ParamField>

<ParamField query="token" type="string" required>
  The same data token used for discovery: embedded in `cdpBaseUrl` and in the `webSocketDebuggerUrl` returned by the discovery endpoint.
</ParamField>

| Status | Meaning |
| - | - |
| `101` | WebSocket upgrade succeeded; CDP messages are now proxied bidirectionally. |
| `401` | The data token is missing or invalid. |
| `404` / `409` / `410` | The session is missing, stopping, or expired. |
| `502` | The cloud backend CDP connection failed before the 101 upgrade. |
| `503` | The session backend is unavailable. |

<RequestExample>
  ```bash cURL theme={null}
  curl -sS "https://api.adscrawl.net/cdp/sessions/SESSION_ID/json/version?token=DATA_TOKEN"
  ```

  ```javascript JavaScript theme={null}
  // Step 1: fetch the discovery document
  const discovery = await fetch(
    "https://api.adscrawl.net/cdp/sessions/SESSION_ID/json/version?token=DATA_TOKEN"
  ).then((response) => response.json());

  // Step 2: open a WebSocket using the pre-built URL
  const socket = new WebSocket(discovery.webSocketDebuggerUrl);

  socket.addEventListener("open", () => {
    console.log("CDP WebSocket connected");
  });
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "Browser": "Chrome/136.0.0.0",
    "Protocol-Version": "1.3",
    "User-Agent": "Mozilla/5.0 ...",
    "V8-Version": "13.6.233.8",
    "WebKit-Version": "537.36 (@revision)",
    "webSocketDebuggerUrl": "wss://api.adscrawl.net/cdp/sessions/SESSION_ID/devtools/browser/BROWSER_ID?token=<data-token>"
  }
  ```
</ResponseExample>
