メインコンテンツへスキップ
POST
/
browser
/
{sessionId}
/
execute
ブラウザセッション内でコードを実行
curl --request POST \
  --url https://api.firecrawl.dev/v2/browser/{sessionId}/execute \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "code": "<string>",
  "language": "node",
  "timeout": 150
}
'
{
  "success": true,
  "stdout": "<string>",
  "result": "<string>",
  "stderr": "<string>",
  "exitCode": 123,
  "killed": true,
  "error": "<string>"
}

ヘッダー

ヘッダー
AuthorizationBearer <API_KEY>
Content-Typeapplication/json

リクエストボディ

パラメータ必須デフォルト説明
codestringはい-実行するコード(1〜100,000 文字)
languagestringいいえ"node"コードの言語:"python""node"、または "bash"(agent-browser CLI コマンド用)
timeoutnumberいいえ-実行タイムアウト時間(秒、1〜300)

レスポンス

FieldTypeDescription
successbooleanコードが正常に実行されたかどうか
stdoutstringコード実行時の標準出力
resultstringコード実行時の標準出力
stderrstringコード実行時の標準エラー出力
exitCodenumber実行されたプロセスの終了コード
killedbooleanプロセスがタイムアウトにより強制終了されたかどうか
errorstring実行が失敗した場合のエラーメッセージ(失敗時のみ含まれる)

リクエスト例

curl -X POST "https://api.firecrawl.dev/v2/browser/550e8400-e29b-41d4-a716-446655440000/execute" \
  -H "Authorization: Bearer $FIRECRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "await page.goto(\"https://example.com\")\ntitle = await page.title()\nprint(title)",
    "language": "python"
  }'

成功時のレスポンス例

{
  "success": true,
  "result": "Example Domain"
}

エラー時のレスポンス例

{
  "success": true,
  "error": "TimeoutError: page.goto: Timeout 30000ms exceeded."
}

承認

Authorization
string
header
必須

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

パスパラメータ

sessionId
string
必須

ブラウザーセッション ID

ボディ

application/json
code
string
必須

ブラウザーサンドボックス内で実行するコード

Required string length: 1 - 100000
language
enum<string>
デフォルト:node

実行するコードの言語。JavaScript の場合は node、agent-browser の CLI コマンドの場合は bash を指定してください。

利用可能なオプション:
python,
node,
bash
timeout
integer

実行タイムアウト(秒)

必須範囲: 1 <= x <= 300

レスポンス

コードは正常に実行されました

success
boolean
stdout
string | null

コード実行時の標準出力

result
string | null

標準出力(stdout の別名)

stderr
string | null

コード実行時の標準エラー出力

exitCode
integer | null

実行プロセスの終了コード

killed
boolean

プロセスがタイムアウトにより強制終了されたかどうか

error
string | null

コードが例外をスローした場合のエラーメッセージ