# 设置 Lighthouse 任务

**API:** Data API

**Endpoint:** `POST /v1/beta/dataforseo/on_page/lighthouse/task_post`

**Tags:** DataForSEO

将 Lighthouse 审计排入队列而不是等待其完成，返回任务 `id`。当审计耗时超过一次工具调用的等待时间时使用；用 `get_dataforseo_on_page_lighthouse_task_get_json` 获取结果，用 `get_dataforseo_on_page_lighthouse_ready` 查看哪些已就绪。采用 DataForSEO 的信封结构：数据位于 `tasks[0].result`，结果状态位于 `tasks[0].status_code`——被拒绝的请求仍会返回 HTTP 200。⚠️ 最终仍是同样 245 KB 的报告，因此上下文成本只是延后，并未避免——请在此处用 `categories` 或 `audits` 收窄，而不是事后再收窄。

### 计费参考

- 计量方式：按上报的响应成本计量。
- 参考请求估算：0.0051 美元。
- 参考客户倍率：1.0。不得对已结算的客户金额再次应用。

仅供参考的元数据，不是账户报价、保证价格或消费上限。资源额度不同于 Felo 额度。最终扣费以 Felo 计费记录为准。

## Base URL

- `https://openapi.felo.ai`

## Authentication

- `FeloBearerAuth` (http bearer, bearer format Felo API Key)
- `FeloApiKey` (apiKey in header `X-API-Key`)

## Request body

Required: **no**

### application/json

Schema:

```json
{
  "type": "array",
  "items": {
    "type": [
      "object",
      "null"
    ],
    "oneOf": [
      {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "description": "<em>目标 URL</em><br><strong>必填字段</strong><br>目标页面应使用绝对 URL 指定（包含 http:// 或 https://）<br>示例：<br><code>https://dataforseo.com/</code>"
          },
          "for_mobile": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "<em>应用移动设备模拟</em><br>可选字段<br>如果设为 <code>true</code>，Lighthouse 将使用移动设备和屏幕模拟，以移动环境测试页面<br>如果设为 <code>false</code>，将提供桌面端的结果<br>默认值：<code>false</code>"
          },
          "categories": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            },
            "description": "<em>Lighthouse 审计类别</em><br>可选字段<br>每个类别是审计项和审计组的集合，会对该部分应用权重和评分（<a href=\"https://github.com/GoogleChrome/lighthouse/blob/master/docs/architecture.md#auditreport-terminology\" target=\"_blank\" rel=\"noopener noreferrer\">参见官方定义</a>）<strong>如果忽略此字段，我们将返回所有类别的数据，除非你指定了 <code>audits</code></strong><br>使用此字段可获取你在此处指定的特定类别的数据<p>可选值：<br><code>seo</code>、<code>performance</code>、<code>best_practices</code>、<code>accessibility</code>"
          },
          "audits": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            },
            "description": "<em>Lighthouse 审计项</em><br>可选字段<br>审计项是 Lighthouse 针对每个特定功能/优化项/指标运行的单项测试，用于得出数值分数（<a href=\"https://github.com/GoogleChrome/lighthouse/blob/master/docs/architecture.md#components--terminology\" rel=\"noopener noreferrer\" target=\"_blank\">参见官方定义</a>）<strong>如果忽略此字段，我们将返回所有审计项的数据</strong><br>使用此字段可获取你在此处指定的特定审计项的数据<p><strong>注意</strong>：有些审计项不属于特定类别，是独立的页面质量衡量指标<p>一般来说，可能有以下几种使用情形：<p>1. 如果忽略 <code>categories</code>，你可以使用此字段仅获取指定审计项的数据<br>例如，如果忽略 <code>\"categories\"</code> 并指定 <code>\"audits\": [\"metrics/cumulative-layout-shift\",\"metrics/largest-contentful-paint\",\"metrics/total-blocking-time\"]</code>，你将仅获取这些审计项的数据<p>2. 如果指定了类别，你可以使用此字段额外接收不属于你所指定类别的审计项<br>例如，如果指定 <code>\"categories\": [\"seo\"]</code> 和 <code>\"audits\": [\"metrics/cumulative-layout-shift\",\"metrics/largest-contentful-paint\",\"metrics/total-blocking-time\"]</code>，你将仅获取 \"performance\" 下的这些审计项，以及 \"seo\" 下的所有审计项<p>你可以<a href=\"/v3/on_page/lighthouse/audits/\">在此处获取所有可能的审计项列表</a>"
          },
          "version": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>Lighthouse 版本</em><br>可选字段<br>指定版本号即可获取特定 Lighthouse 版本的结果<br>可用版本列表可通过 <a href=\"/v3/on_page/lighthouse/versions/\" target=\"_blank\" rel=\"noopener noreferrer\">Lighthouse Versions 端点</a>获取"
          },
          "language_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>Lighthouse 语言名称</em><br>可选字段<br>你可以单独向 <code>https://api.dataforseo.com/v3/on_page/lighthouse/languages</code> 发起请求，获取搜索引擎可用语言及其 <code>language_name</code> 的列表<br>默认值：<br><code class=\"long-string\">English</code>"
          },
          "language_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>Lighthouse 语言代码</em><br>可选字段<br>你可以单独向 <code>https://api.dataforseo.com/v3/on_page/lighthouse/languages</code> 发起请求，获取搜索引擎可用语言及其 <code>language_code</code> 的列表<br>默认值：<br><code class=\"long-string\">en</code>"
          },
          "custom_user_agent": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>自定义用户代理</em><br>可选字段<br>指定浏览器在运行 Lighthouse 审计时使用的自定义用户代理；<br>最多可指定 254 个字符；"
          },
          "browser_screen_width": {
            "type": [
              "integer",
              "null"
            ],
            "description": "<em>浏览器屏幕宽度</em><br>可选字段<br>设置用于 Lighthouse 审计的浏览器屏幕宽度，以模拟特定设备；<br>可在以下范围内指定：<code>240–9999</code>；",
            "format": "int64"
          },
          "browser_screen_height": {
            "type": [
              "integer",
              "null"
            ],
            "description": "<em>浏览器屏幕高度</em><br>可选字段<br>设置用于 Lighthouse 审计的浏览器屏幕高度，以模拟特定设备；<br>可在以下范围内指定：<code>240–9999</code>；"
          },
          "browser_screen_scale_factor": {
            "type": [
              "number",
              "null"
            ],
            "description": "<em>浏览器屏幕缩放比例</em><br>可选字段<br>设置用于 Lighthouse 审计的浏览器的设备像素比；<br>可在以下范围内指定：<code>0.5–3</code>；"
          },
          "browser_network_throttling_method": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>浏览器网络节流方法</em><br>可选字段<br>定义 Lighthouse 审计期间应用节流的方法；<br>可选值：<br><code>simulate</code> - 在不施加显式节流的情况下计算预估的性能指标；<br><code>devtools</code> - 应用 <code>browser_network_throttling</code> 和 <code>browser_cpu_throttling_multiplier</code> 中指定的节流设置；<br><code>provided</code> - 使用抓取环境的网络状况；"
          },
          "browser_cpu_throttling_multiplier": {
            "type": [
              "number",
              "null"
            ],
            "description": "<em>浏览器 CPU 节流倍数</em><br><strong>当 <code>browser_network_throttling_method</code> 设为 <code>devtools</code> 时为必填；</strong><br>设置 CPU 节流倍数，以在 Lighthouse 审计期间模拟设备性能状况；<br>可在以下范围内指定：<code>1–4</code>；<br><strong>注意：</strong>仅当 <code>browser_network_throttling_method</code> 设为 <code>devtools</code> 时才会应用此参数；"
          },
          "browser_network_throttling": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>浏览器网络节流</em><br><strong>当 <code>browser_network_throttling_method</code> 设为 <code>devtools</code> 时为必填；</strong><br>设置网络节流配置文件，以在 Lighthouse 审计期间模拟连接速度状况；<br>可选值：<code>no_throttling</code>、<code>fast_4g</code>、<code>slow_4g</code>、<code>regular_3g</code>、<code>pc</code>；<br><strong>注意：</strong>仅当 <code>browser_network_throttling_method</code> 设为 <code>devtools</code> 时才会应用此参数；"
          },
          "tag": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>用户自定义任务标识符</em><br>可选字段<br><em>字符数上限为 255</em><br>可使用此参数标识任务，并将其与结果对应<br>可在响应的 <code>data</code> 对象中找到指定的 <code>tag</code> 值"
          },
          "pingback_url": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>已完成任务的通知 URL</em><br>可选字段<br>任务完成后，我们会向你指定的 URL 发送 GET 请求进行通知<br>你可以将 ‘$id’ 字符串用作 <code>$id</code> 变量，将 ‘$tag’ 用作 URL 编码的 <code>$tag</code> 变量。发送请求前，我们会设置必要的值。<br>示例：<br><code>http://your-server.com/pingscript?id=$id</code><br><code>http://your-server.com/pingscript?id=$id&amp;tag=$tag</code><br><strong>注意：</strong><code>pingback_url</code> 中的特殊字符会被 URL 编码；<br>例如，<code>#</code> 字符会被编码为 <code>%23</code>。更多信息请参阅我们的<a href=\"https://dataforseo.com/help-center/pingbacks-postbacks-with-dataforseo-api\" target=\"_blank\" rel=\"noopener noreferrer\">帮助中心</a>"
          }
        },
        "example": [
          {
            "url": "https://dataforseo.com",
            "for_mobile": true,
            "tag": "some_string_123",
            "pingback_url": "https://your-server.com/pingscript?id=$id&tag=$tag"
          }
        ]
      }
    ]
  },
  "example": [
    {
      "url": "https://dataforseo.com",
      "for_mobile": true,
      "tag": "some_string_123",
      "pingback_url": "https://your-server.com/pingscript?id=$id&tag=$tag"
    }
  ]
}
```

## Responses

### 200 — 操作成功

Headers:
- `X-Request-Id` (string) — 联系 Felo 支持时需提供的请求标识符。

**application/json**

Schema: object | null

```json
{
  "type": [
    "object",
    "null"
  ],
  "oneOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_OnPageLighthouseTaskPostResponseInfo"
    }
  ]
}
```

### 400 — 无法处理该请求。请检查请求参数。

### 401 — 需要有效的 Felo API 密钥。

### 402 — 由于未满足计费要求，请求无法继续。

### 403 — 该账户无权执行此操作。

### 429 — 已达到请求或支出限额。

### 502 — 服务无法完成该请求。

### 503 — API 或计费服务暂时不可用。

### 504 — 服务在处理请求时超时。

### default — 错误响应；上游透传响应可能采用提供方格式

**application/json**

Schema:

```json
{}
```

## Schema definitions

### Response36Afe1097B20_BaseResponseInfo

`#/components/schemas/Response36Afe1097B20_BaseResponseInfo`

```json
{
  "properties": {
    "version": {
      "type": [
        "string",
        "null"
      ],
      "description": "API 的当前版本"
    },
    "status_code": {
      "type": [
        "integer",
        "null"
      ],
      "description": "通用状态码\n完整响应码列表见此处"
    },
    "status_message": {
      "type": [
        "string",
        "null"
      ],
      "description": "通用信息性消息\n完整的一般信息性消息列表见此处"
    },
    "time": {
      "type": [
        "string",
        "null"
      ],
      "description": "总执行时间，秒"
    },
    "cost": {
      "type": [
        "number",
        "null"
      ],
      "description": "任务总费用，美元",
      "format": "double"
    },
    "tasks_count": {
      "type": [
        "integer",
        "null"
      ],
      "description": "tasks 数组中的任务数",
      "format": "int64"
    },
    "tasks_error": {
      "type": [
        "integer",
        "null"
      ],
      "description": "tasks 数组中返回错误的任务数",
      "format": "int64"
    }
  }
}
```

### Response36Afe1097B20_BaseResponseTaskInfo

`#/components/schemas/Response36Afe1097B20_BaseResponseTaskInfo`

```json
{
  "properties": {
    "id": {
      "type": [
        "string",
        "null"
      ],
      "description": "任务标识符\n我们系统中 UUID 格式的唯一任务标识符"
    },
    "status_code": {
      "type": [
        "integer",
        "null"
      ],
      "description": "任务的状态码\n由 DataForSEO 生成，范围如下：10000-60000\n完整响应码列表见此处"
    },
    "status_message": {
      "type": [
        "string",
        "null"
      ],
      "description": "任务的信息性消息\n完整的一般信息性消息列表见此处"
    },
    "time": {
      "type": [
        "string",
        "null"
      ],
      "description": "执行时间，秒"
    },
    "cost": {
      "type": [
        "number",
        "null"
      ],
      "description": "任务总费用，美元",
      "format": "double"
    },
    "result_count": {
      "type": [
        "integer",
        "null"
      ],
      "description": "result 数组中的元素数",
      "format": "int64"
    },
    "path": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "string",
          "null"
        ]
      },
      "description": "URL 路径"
    },
    "data": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": {
        "type": [
          "object",
          "null"
        ]
      },
      "description": "包含你在 POST 请求中指定的相同参数"
    }
  }
}
```

### Response36Afe1097B20_OnPageLighthouseTaskPostResponseInfo

`#/components/schemas/Response36Afe1097B20_OnPageLighthouseTaskPostResponseInfo`

```json
{
  "type": "object",
  "allOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_BaseResponseInfo"
    },
    {
      "type": "object",
      "properties": {
        "tasks": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": [
              "object",
              "null"
            ],
            "oneOf": [
              {
                "$ref": "#/components/schemas/Response36Afe1097B20_OnPageLighthouseTaskPostTaskInfo"
              }
            ]
          },
          "description": "<em>任务数组</em>"
        }
      }
    }
  ]
}
```

### Response36Afe1097B20_OnPageLighthouseTaskPostTaskInfo

`#/components/schemas/Response36Afe1097B20_OnPageLighthouseTaskPostTaskInfo`

```json
{
  "type": "object",
  "allOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_BaseResponseTaskInfo"
    },
    {
      "type": "object",
      "properties": {
        "result": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": {
              "type": [
                "object",
                "null"
              ]
            }
          }
        }
      }
    }
  ]
}
```
