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

# Close Tab

> Close a tab by pageId.

## Overview

The `DELETE /browser/sessions/{id}/pages/{pageId}` endpoint closes a single tab in the session. The tab is identified by its CDP target identifier, which you can obtain from `POST /browser/sessions/{id}/pages` or `GET /browser/sessions/{id}/pages`.

Closing the currently active tab promotes another tab to active. You cannot close the last remaining tab in a session — doing so returns `409 Conflict`.

## Path Parameters

<ParamField path="id" type="string" required={true}>
  Browser session ID (UUID). Create via `POST /browser/sessions`.
</ParamField>

<ParamField path="pageId" type="string" required={true}>
  CDP target identifier of the tab to close. 32-character uppercase hex. Obtain via `POST /pages` or `GET /pages`.
</ParamField>

## Body

No request body. Send an empty request.

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.scrapengine.io/api/v1/browser/sessions/0f2b1f6a-88ac-4d25-bc58-67a6f4b4a001/pages/EA5E9AA71C7A91C467F8CDBB266EE5E0" \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    "https://api.scrapengine.io/api/v1/browser/sessions/0f2b1f6a-88ac-4d25-bc58-67a6f4b4a001/pages/EA5E9AA71C7A91C467F8CDBB266EE5E0",
    {
      method: "DELETE",
      headers: {
        "Authorization": "Bearer YOUR_API_KEY",
      },
    },
  );
  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.scrapengine.io/api/v1/browser/sessions/0f2b1f6a-88ac-4d25-bc58-67a6f4b4a001/pages/EA5E9AA71C7A91C467F8CDBB266EE5E0"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY",
  }

  response = requests.delete(url, headers=headers)
  data = response.json()
  ```
</CodeGroup>

## Response

### Success Response (200)

<ResponseField name="success" type="boolean">
  `true` when the tab was closed.
</ResponseField>

<ResponseField name="pageId" type="string">
  CDP target identifier of the closed tab (echoed back for correlation).
</ResponseField>

**Example Response:**

```json theme={null}
{
  "success": true,
  "pageId": "EA5E9AA71C7A91C467F8CDBB266EE5E0"
}
```

### Error Responses

| Status | Description                                                                                          |
| ------ | ---------------------------------------------------------------------------------------------------- |
| `401`  | Unauthorized — invalid or missing API key.                                                           |
| `404`  | Session not found, not owned by the caller, or no tab with the given `pageId` exists in the session. |
| `408`  | Navigation timeout while processing the close (rare — occurs when `beforeunload` handlers block).    |
| `409`  | Cannot close the last remaining tab in the session. Close the session instead.                       |
| `503`  | The browser session is temporarily unreachable.                                                      |

## Notes

* If the closed tab was active, another tab is promoted to active. Call `GET /browser/sessions/{id}/pages` to inspect the new active tab.
* To end a session entirely, call `DELETE /browser/sessions/{id}` rather than closing the last tab.
