跳转到内容
EN

操作手机屏幕

先调用「创建沙箱」,用返回的 sandboxID 替换 sbx_123。

POST/sandbox/v1/sandboxes/{sandboxID}/act● 支持

请求参数

  • sandboxIDstring必填

    path: 沙箱 ID。

返回

200

错误按 E2B 格式返回,参见 错误码

请求示例

curl
# 先调用「创建沙箱」,用返回的 sandboxID 替换 sbx_123。
curl https://api.deepraxis.com/sandbox/v1/sandboxes/sbx_123/act \
  -H "X-API-Key: $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"snapshot"}'
Python
# 先调用「创建沙箱」,用返回的 sandboxID 替换 sbx_123。
import requests

api_key = "$PRAXIS_API_KEY"

# Call /sandbox/v1 directly over HTTP.
resp = requests.post(
    "https://api.deepraxis.com/sandbox/v1/sandboxes/sbx_123/act",
    headers={"X-API-Key": api_key},
    json={"type": "snapshot"},
)
print(resp.status_code, resp.text)
TypeScript
// 先调用「创建沙箱」,用返回的 sandboxID 替换 sbx_123。
const apiKey = "$PRAXIS_API_KEY";

// Call /sandbox/v1 directly over HTTP.
const resp = await fetch(`https://api.deepraxis.com/sandbox/v1/sandboxes/sbx_123/act`, {
  method: "POST",
  headers: { "X-API-Key": apiKey, "Content-Type": "application/json" },
  body: JSON.stringify({ type: "snapshot" }),
});
console.log(resp.status, await resp.text());

响应示例 200

{
  "type": "snapshot",
  "snapshot": "- scrollable [ref=e1]\n  - text \"设置\"\n  - clickable [ref=e2]\n    - text \"搜索设置\"\n  - scrollable [ref=e3]\n    - clickable [ref=e4]\n      - text \"网络和互联网\"\n      - text \"移动网络、WLAN、热点\"\n    - clickable [ref=e5]\n      - text \"已连接的设备\"\n      - text \"蓝牙、配对\"\n    - clickable [ref=e6]\n      - text \"应用\"\n      - text \"最近使用的应用、默认应用\"\n    - clickable [ref=e7]\n      - text \"通知\"\n      - text \"历史通知、对话\"\n    - clickable [ref=e8]\n      - text \"电池\"\n      - text \"93%\"\n    - clickable [ref=e9]\n      - text \"存储\"\n      - text \"已使用 2% - 还剩 29.48 GB\"\n    - clickable [ref=e10]\n      - text \"提示音和振动\"\n      - text \"音量、振动、勿扰\"\n    - clickable [ref=e11]\n      - text \"显示\"\n      - text \"深色主题、字体大小、亮度\"\n    - clickable [ref=e12]\n      - text \"壁纸\"\n      - text \"主屏幕、锁定屏幕\"\n    - clickable [ref=e13]\n      - text \"无障碍\"\n      - text \"显示、互动、音频\"\n    - clickable [ref=e14]\n      - text \"安全和隐私\"\n      - text \"应用安全性、设备锁定、权限\"\n    - clickable [ref=e15]\n      - text \"位置信息\"\n      - text \"已开启 / 2 个应用有权访问位置信息\"\n    - clickable [ref=e16]\n      - text \"安全和紧急情况\"\n      - text \"紧急求救、医疗信息、警报\"\n    - clickable [ref=e17]\n      - text \"密码、通行密钥和自动填充\"\n      - text \"登录和自动填充方面的建议\"\n    - clickable [ref=e18]\n      - text \"系统\"\n      - text \"语言、手势、时间、备份\"\n    - clickable [ref=e19]\n      - text \"关于本机\"\n      - text \"wuying android14\"",
  "refs": 19,
  "truncated": false,
  "package": "com.android.settings"
}

响应

HTTP 200

The action’s result: the UI hierarchy and refs for snapshot, image bytes for screenshot, the applied duration for a long press, or an acknowledgement with no data.

application/json

名称 类型 说明
type string Result kind; "snapshot" for this shape. / Result kind; "screenshot" for this shape. / Result kind; "ok" for an action with no result of its own. / Result kind; "wait" for the wait action.
snapshot string The screen as an indented text list, one line per meaningful node: its role, its text in quotes and, for a node you can act on, its ref, such as - button "登录" [ref=e3]. Password text is masked.
refs integer How many nodes received a ref that tap, long_press, scroll and type accept.
truncated boolean True when the hierarchy was too large and was cut; the returned refs still name their nodes.
package string Package name of the app that was in the foreground at the snapshot, such as com.android.settings.
mediaType string Image MIME type of the encoded bytes; image/jpeg. In code mode, return "data:" + mediaType + ";base64," + data to see the image.
data string Base64-encoded image bytes; decode before saving or viewing.
width integer Image width in pixels.
height integer Image height in pixels.
bytes integer Decoded image size in bytes.
ms integer How long the phone took to run the action, in milliseconds. / How long the call waited, in milliseconds; echoes the requested ms.