macOS 应用通过 WKWebView 嵌入 Agent 控制的 Canvas 面板,用于 HTML/CSS/JS、A2UI 和小型交互 UI。

文件存储与 URL Scheme

Canvas 状态存储在:

~/Library/Application Support/OpenClaw/canvas/<session>/...

通过自定义 URL scheme 访问:

openclaw-canvas://<session>/<path>

示例:

  • openclaw-canvas://main/ → <canvasRoot>/main/index.html
  • openclaw-canvas://main/assets/app.css → 对应 CSS 文件

根目录无 index.html 时显示内置脚手架页面。

面板行为

  • 无边框、可调整大小,锚定在菜单栏附近
  • 每个会话记住尺寸/位置
  • 本地 canvas 文件变更时自动重载
  • 同一时间只显示一个 Canvas 面板

Settings → Allow Canvas 可禁用 Canvas,禁用后命令返回 CANVAS_DISABLED。

Agent API

openclaw nodes canvas present --node <id>
openclaw nodes canvas navigate --node <id> --url "/"
openclaw nodes canvas eval --node <id> --js "document.title"
openclaw nodes canvas snapshot --node <id>

canvas.navigate 接受本地 canvas 路径、http(s) URL 和 file:// URL。

A2UI 集成

A2UI 由 Gateway canvas host 托管,默认 URL:

http://<gateway-host>:18789/__openclaw__/a2ui/

当前支持 A2UI v0.8 消息:beginRendering、surfaceUpdate、dataModelUpdate、deleteSurface。

# 快速测试
openclaw nodes canvas a2ui push --node <id> --text "Hello from A2UI"

从 Canvas 触发 Agent

// Canvas 内 JS
window.location.href = "openclaw://agent?message=Review%20this%20design";

无有效 key 时需用户确认。

安全说明

  • Canvas scheme 阻止目录遍历,文件必须在会话根目录下
  • 外部 http(s) URL 仅在显式导航时允许

相关链接