与抓取任务关联的浏览器会话进行交互
curl --request POST \
--url https://api.firecrawl.dev/v2/scrape/{jobId}/interact \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "<string>",
"language": "node",
"origin": "<string>",
"timeout": 30
}
'import requests
url = "https://api.firecrawl.dev/v2/scrape/{jobId}/interact"
payload = {
"code": "<string>",
"language": "node",
"origin": "<string>",
"timeout": 30
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({code: '<string>', language: 'node', origin: '<string>', timeout: 30})
};
fetch('https://api.firecrawl.dev/v2/scrape/{jobId}/interact', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.firecrawl.dev/v2/scrape/{jobId}/interact",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => '<string>',
'language' => 'node',
'origin' => '<string>',
'timeout' => 30
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.firecrawl.dev/v2/scrape/{jobId}/interact"
payload := strings.NewReader("{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"origin\": \"<string>\",\n \"timeout\": 30\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.firecrawl.dev/v2/scrape/{jobId}/interact")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"origin\": \"<string>\",\n \"timeout\": 30\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firecrawl.dev/v2/scrape/{jobId}/interact")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"origin\": \"<string>\",\n \"timeout\": 30\n}"
response = http.request(request)
puts response.read_body{
"cdpUrl": "<string>",
"error": "<string>",
"exitCode": 123,
"interactiveLiveViewUrl": "<string>",
"killed": true,
"liveViewUrl": "<string>",
"output": "<string>",
"result": "<string>",
"stderr": "<string>",
"stdout": "<string>",
"success": true
}{
"error": "Invalid job ID format.",
"success": false
}{
"error": "Payment required to access this resource.",
"success": false
}{
"error": "Forbidden.",
"success": false
}{
"error": "Job not found.",
"success": false
}{
"error": "Replay context is unavailable for this scrape job. Please rerun the scrape.",
"success": false
}{
"error": "Browser session has been destroyed.",
"success": false
}{
"error": "You have reached the maximum number of active browser sessions.",
"success": false
}{
"error": "Failed to execute code in browser session.",
"success": false
}交互端点
与已抓取的页面交互
在绑定到抓取任务的浏览器会话中执行代码或 AI prompt。
POST
/
scrape
/
{jobId}
/
interact
与抓取任务关联的浏览器会话进行交互
curl --request POST \
--url https://api.firecrawl.dev/v2/scrape/{jobId}/interact \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "<string>",
"language": "node",
"origin": "<string>",
"timeout": 30
}
'import requests
url = "https://api.firecrawl.dev/v2/scrape/{jobId}/interact"
payload = {
"code": "<string>",
"language": "node",
"origin": "<string>",
"timeout": 30
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({code: '<string>', language: 'node', origin: '<string>', timeout: 30})
};
fetch('https://api.firecrawl.dev/v2/scrape/{jobId}/interact', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.firecrawl.dev/v2/scrape/{jobId}/interact",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'code' => '<string>',
'language' => 'node',
'origin' => '<string>',
'timeout' => 30
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.firecrawl.dev/v2/scrape/{jobId}/interact"
payload := strings.NewReader("{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"origin\": \"<string>\",\n \"timeout\": 30\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.firecrawl.dev/v2/scrape/{jobId}/interact")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"origin\": \"<string>\",\n \"timeout\": 30\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firecrawl.dev/v2/scrape/{jobId}/interact")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"origin\": \"<string>\",\n \"timeout\": 30\n}"
response = http.request(request)
puts response.read_body{
"cdpUrl": "<string>",
"error": "<string>",
"exitCode": 123,
"interactiveLiveViewUrl": "<string>",
"killed": true,
"liveViewUrl": "<string>",
"output": "<string>",
"result": "<string>",
"stderr": "<string>",
"stdout": "<string>",
"success": true
}{
"error": "Invalid job ID format.",
"success": false
}{
"error": "Payment required to access this resource.",
"success": false
}{
"error": "Forbidden.",
"success": false
}{
"error": "Job not found.",
"success": false
}{
"error": "Replay context is unavailable for this scrape job. Please rerun the scrape.",
"success": false
}{
"error": "Browser session has been destroyed.",
"success": false
}{
"error": "You have reached the maximum number of active browser sessions.",
"success": false
}{
"error": "Failed to execute code in browser session.",
"success": false
}使用此端点可继续与由先前抓取初始化的同一浏览器状态进行交互。必须提供
有关详细使用方式和示例,请参见 Interact 功能指南。
code 或 prompt 之一,不能同时提供两者。
POST /v2/scrape/{jobId}/interact 负责整个生命周期:
- 如果此抓取任务尚未存在浏览器会话,Firecrawl 会在与原始抓取相同的页面状态下创建一个会话。
- 提供
code时,Firecrawl 会在浏览器沙箱中运行它;提供prompt时,AI 代理会使用自然语言自动完成该任务。 - 后续在同一
jobId上调用POST /interact时,会复用同一个实时浏览器状态。
DELETE /v2/scrape/{jobId}/interact 以停止该会话。
路径参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
jobId | string (UUID) | 是 | 抓取响应中的 data.metadata.scrapeId 对应的抓取任务 ID |
请求体
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
code | string | 否 | — | 在浏览器沙箱中执行的代码 (1–100,000 个字符) 。如果未设置 prompt,则为必填。 |
prompt | string | 否 | — | 提供给 AI 代理的自然语言任务 (1–10,000 个字符) 。如果未设置 code,则为必填。 |
language | string | 否 | "node" | "python"、"node" 或 "bash" 之一。仅在使用 code 时生效。 |
timeout | number | 否 | 30 | 执行超时时间 (秒) (1–300) 。 |
origin | string | 否 | — | 用于遥测的可选来源标识。 |
响应
| 字段 | 类型 | 描述 |
|---|---|---|
success | boolean | 执行是否在无错误的情况下完成 |
cdpUrl | string | 浏览器会话的原始 Chrome DevTools Protocol (CDP) WebSocket URL。可通过 Playwright、Puppeteer 或任何 CDP 客户端直接连接 |
liveViewUrl | string | 浏览器会话的只读实时视图 URL |
interactiveLiveViewUrl | string | 交互式实时视图 URL (查看者可控制浏览器) |
output | string | AI 代理的最终响应 (仅在使用 prompt 时返回) |
stdout | string | 代码执行的标准输出 |
result | string | 返回值——对 Node.js 而言是最后一个表达式的值,对 prompt 而言是最终页面快照 |
stderr | string | 标准错误输出 |
exitCode | number | 执行退出码 (0 = 成功) |
killed | boolean | 执行是否因超时而终止 |
error | string | 错误信息 (仅在失败时返回) |
示例请求 (代码)
curl -X POST "https://api.firecrawl.dev/v2/scrape/550e8400-e29b-41d4-a716-446655440000/interact" \
-H "Authorization: Bearer $FIRECRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "const title = await page.title(); JSON.stringify({ title });",
"language": "node",
"timeout": 30
}'
示例响应 (代码)
{
"success": true,
"cdpUrl": "wss://browser.firecrawl.dev/...",
"liveViewUrl": "https://liveview.firecrawl.dev/...",
"interactiveLiveViewUrl": "https://liveview.firecrawl.dev/...",
"stdout": "",
"result": "{\"title\":\"Example Domain\"}",
"stderr": "",
"exitCode": 0,
"killed": false
}
示例请求 (Prompt)
curl -X POST "https://api.firecrawl.dev/v2/scrape/550e8400-e29b-41d4-a716-446655440000/interact" \
-H "Authorization: Bearer $FIRECRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Find the pricing section and tell me the price of the Pro plan",
"timeout": 60
}'
示例响应 (Prompt)
{
"success": true,
"cdpUrl": "wss://browser.firecrawl.dev/...",
"liveViewUrl": "https://liveview.firecrawl.dev/...",
"interactiveLiveViewUrl": "https://liveview.firecrawl.dev/...",
"output": "The Pro plan costs $49/month and includes unlimited scrapes, priority support, and custom integrations.",
"stdout": "...",
"result": "...",
"stderr": "",
"exitCode": 0,
"killed": false
}
错误代码
| 状态 | 描述 |
|---|---|
402 | 浏览器会话额度不足 |
403 | 抓取任务属于其他团队 |
404 | 未找到抓取任务 |
409 | 回放上下文不可用——请重新运行抓取后重试 |
410 | 浏览器会话已被销毁 |
429 | 已达到浏览器会话的最大并发数 |
502 | 浏览器服务或 AI 代理执行失败 |
503 | 浏览器功能未配置 (仅限自托管) |
授权
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
路径参数
抓取任务 ID
请求体
application/json
响应
代码执行成功
浏览器会话的原始 Chrome DevTools Protocol (CDP) WebSocket URL。可使用它通过 Playwright、Puppeteer 或任何 CDP 客户端直接连接。
如果代码引发异常时的错误消息
执行进程的退出代码
交互式实时视图 URL(观看者可以控制浏览器)
进程是否因超时而被终止
浏览器会话的只读实时视图 URL
AI 代理的最终响应(仅在使用 prompt 时出现)
标准输出(stdout 的别名)
代码执行的标准错误输出
代码执行的标准输出
⌘I

