> ## Documentation Index
> Fetch the complete documentation index at: https://student-213fb9fc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建浏览器会话

> 在沙盒环境中启动一个新的云浏览器会话。

<div id="headers">
  ## 请求头
</div>

| Header          | 值                  |
| --------------- | ------------------ |
| `Authorization` | `Bearer <API_KEY>` |
| `Content-Type`  | `application/json` |

<div id="request-body">
  ## 请求体
</div>

| 参数                    | 类型      | 必填  | 默认值    | 描述                                                                       |
| --------------------- | ------- | --- | ------ | ------------------------------------------------------------------------ |
| `ttl`                 | number  | 否   | 300    | 会话总有效期（秒）（30-3600）                                                       |
| `activityTtl`         | number  | 否   | 60     | 会话在销毁前允许的不活动时长（秒）（10-3600）                                               |
| `profile`             | object  | 否   | —      | 启用跨会话的持久化存储。参见下文。                                                        |
| `profile.name`        | string  | 是\* | —      | 配置文件名称（1-128 字符）。具有相同名称的会话共享存储。                                          |
| `profile.saveChanges` | boolean | 否   | `true` | 当为 `true` 时，在关闭时会将浏览器状态保存回该配置文件。设为 `false` 可在不写入的情况下加载已有数据。同一时间只允许一个保存方。 |

<div id="response">
  ## 响应
</div>

| 字段                       | 类型      | 描述                         |
| ------------------------ | ------- | -------------------------- |
| `success`                | boolean | 会话是否创建成功                   |
| `id`                     | string  | 唯一的会话标识符                   |
| `cdpUrl`                 | string  | 用于 CDP 连接的 WebSocket 地址    |
| `liveViewUrl`            | string  | 用于实时查看会话的 URL              |
| `interactiveLiveViewUrl` | string  | 用于与会话进行实时交互（点击、输入、滚动）的 URL |
| `expiresAt`              | string  | 会话基于 TTL 的过期时间             |

<div id="example-request">
  ### 请求示例
</div>

```bash theme={null}
curl -X POST "https://api.firecrawl.dev/v2/browser" \
  -H "Authorization: Bearer $FIRECRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "ttl": 120
  }'
```

<div id="example-response">
  ### 响应示例
</div>

```json theme={null}
{
  "success": true,
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "cdpUrl": "wss://cdp-proxy.firecrawl.dev/cdp/550e8400-e29b-41d4-a716-446655440000",
  "liveViewUrl": "https://liveview.firecrawl.dev/550e8400-e29b-41d4-a716-446655440000",
  "interactiveLiveViewUrl": "https://liveview.firecrawl.dev/550e8400-e29b-41d4-a716-446655440000?interactive=true"
}
```


## OpenAPI

````yaml zh/api-reference/v2-openapi.json post /browser
openapi: 3.0.0
info:
  title: Firecrawl API
  version: v2
  description: 用于与 Firecrawl 服务交互，执行网页抓取和爬取任务的 API。
  contact:
    name: Firecrawl Support
    url: https://firecrawl.dev/support
    email: support@firecrawl.dev
servers:
  - url: https://api.firecrawl.dev/v2
security:
  - bearerAuth: []
paths:
  /browser:
    post:
      tags:
        - Browser
      summary: 创建浏览器会话
      operationId: createBrowserSession
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ttl:
                  type: integer
                  default: 300
                  minimum: 30
                  maximum: 3600
                  description: 浏览器会话的最大存活时长（秒）
                activityTtl:
                  type: integer
                  minimum: 10
                  maximum: 3600
                  description: 会话在空闲被销毁前的超时时长（秒）
                streamWebView:
                  type: boolean
                  default: true
                  description: 是否以流式方式传输浏览器的实时画面
                profile:
                  type: object
                  description: 在会话之间启用持久化存储。在一个会话中保存的数据，之后在使用相同名称的会话中可以重新加载。
                  properties:
                    name:
                      type: string
                      minLength: 1
                      maxLength: 128
                      description: 配置文件的名称。使用相同名称的会话将共享同一存储空间。
                    saveChanges:
                      type: boolean
                      default: true
                      description: >-
                        当为 true 时，浏览器状态在关闭时会写回到该配置（profile）。当为 false
                        时，只会读取已有数据而不会写入。可以同时存在多个不持久化会话，但同一时间只能有一个持久化会话。
                  required:
                    - name
      responses:
        '200':
          description: 浏览器会话创建成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  id:
                    type: string
                    description: 会话的唯一标识符
                  cdpUrl:
                    type: string
                    description: 用于访问 Chrome DevTools Protocol 的 WebSocket 地址
                  liveViewUrl:
                    type: string
                    description: 用于实时查看浏览会话的 URL
                  interactiveLiveViewUrl:
                    type: string
                    description: 用于实时与浏览器会话交互的 URL（点击、输入、滚动）
                  expiresAt:
                    type: string
                    format: date-time
                    description: 会话按 TTL 计算的过期时间
        '402':
          description: 需付费
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Payment required to access this resource.
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````