简介
OpenClaw官方生态的Canvas应用平台,支持在本地构建、部署富交互可视化应用,实现Agent与UI的双向实时通信。
原始描述
Canvas as an app platform. Build, store, and run rich visual apps on the OpenClaw Canvas.
通过你的 Agent 添加
点「快速安装」复制一段指令,粘给你正在用的 Agent(Claude Code、Codex、OpenClaw 等),它会自己完成安装。
或者手动安装
包里是 SKILL.md 加作者附带的文件,解压后目录名就是技能名。
技能申请的权限由作者决定,装之前请确认它能读什么、能执行什么。
中文使用说明 来自收录源
核心用法
Canvas OS 是 OpenClaw 生态中的可视化应用平台,将 Canvas 面板转化为富交互 UI 窗口。用户通过三类命令与系统交互:"Open [app]" 启动本地服务器并导航 Canvas 加载应用;"Build me a [type]" 从模板创建新应用;"Update [element]" 通过 JS eval 实时注入数据修改界面。应用采用标准 HTML/CSS/JS 技术栈,存储于 ~/.openclaw/workspace/apps// 目录,通过 Python http.server 提供 localhost 服务,最终由 Agent 调用 openclaw nodes canvas navigate 在 Canvas 面板上渲染。
技术实现上,Canvas OS 提供三种加载策略:localhost 服务器适合复杂应用与外部资源;直接 HTML 注入适用于快速演示,通过 canvas.eval 执行 document.write()() 绕过文件路径安全限制;Data URL 则用于小型自包含内容。应用需暴露 window.app API 对象供 Agent 调用,同时支持通过 openclaw://agent 深度链接实现用户操作回调,形成完整的双向通信闭环。
显著优点
原生集成优势:深度绑定 OpenClaw 生态,与 Agent 系统无缝协作,命令语义自然("Show my dashboard"),降低学习成本。技术栈普适:基于标准 Web 技术,无需学习专有框架,前端开发者可立即上手。实时交互能力:JS eval 注入机制支持毫秒级界面更新,远优于传统轮询或页面刷新方案。模板化快速启动:内置 Dashboard、Tracker 等模板,配合自包含 HTML 设计(内联 CSS/JS),单文件即可运行。安全边界清晰:服务仅限 localhost,无公网暴露风险;文件操作限定用户目录,权限需求最小化。
潜在缺点与局限性
平台锁定严重:完全依赖 OpenClaw 专有生态,Canvas 面板、CLI 命令、、openclaw-canvas:// URL 方案均为平台特有,无法迁移至其他 Agent 系统。文件路径限制:Canvas 安全沙箱彻底阻断 file://// 访问,强制要求 localhost 或 HTML 注入,增加了架构复杂度。URL 方案缺陷:官方文档明确指出 openclaw-canvas:// 存在实现问题,需回退到 http://localhost 方案。注入安全风险:canvas-inject.py 仅转义反引号,HTML 内容中的 $ 等模板字符串特殊字符可能引发意外行为。调试体验受限:Canvas 面板内嵌于 OpenClaw 应用,缺乏浏览器 DevTools 的完整调试能力,问题排查依赖日志与试错。
适合的目标群体
OpenClaw 深度用户:已构建 Agent 工作流,需要将文本交互升级为可视化界面的高级用户。快速原型开发者:需要为演示、监控场景快速搭建数据看板,而非构建生产级 Web 应用的技术人员。个人效率工具爱好者:希望将习惯追踪、计时器等工具集成到统一 Agent 界面的生产力用户。前端技术背景者:熟悉 HTML/CSS/JS,希望利用现有技能扩展 Agent 能力的开发者。
不适合:需要跨平台部署的企业用户、追求浏览器原生体验的 Web 开发者、对供应商锁定敏感的开源倡导者。
使用风险
性能风险:Python http.server 为单线程阻塞模型,高并发或大量静态资源请求时响应迟缓;每个应用占用独立端口,长期运行可能导致端口耗尽。依赖稳定性:核心功能依赖 OpenClaw CLI 的持续兼容性,平台升级可能破坏现有命令;canvas.eval 等内部 API 无公开稳定性承诺。数据持久化局限:应用状态依赖 data.json 文件,无内置同步或备份机制,设备故障易致数据丢失。进程管理粗糙:kill -9 强制终止可能遗留僵尸进程或临时文件,建议配合 lsof 定期检查端口占用。安全细节待完善:缺乏输入验证(app-name 未过滤路径遍历字符)、HTML 转义不完整,在共享或多用户环境中需谨慎使用。
技能正文
name: canvas-os description: Canvas as an app platform. Build, store, and run rich visual apps on the OpenClaw Canvas. homepage: https://www.clawhub.ai/fraction12/canvas-os metadata: openclaw: emoji: "🖥️" category: ui requires: bins: ["python3"]
Canvas OS
Canvas as an app platform. Build, store, and run rich visual apps on the OpenClaw Canvas.
Philosophy
You are an OS. Canvas is the window. Apps are built locally and run on Canvas.
Rich HTML/CSS/JS UIs — not just text. Full interactivity, animations, live data.
Quick Commands
| Command | What Jarvis Does |
|---|---|
| "Open [app]" | Start server, navigate Canvas, inject data |
| "Build me a [type]" | Create app from template, open it |
| "Update [element]" | Inject JS to modify live |
| "Show [data] on canvas" | Quick A2UI display |
| "Close canvas" | Stop server, hide Canvas |
How It Works
Key principle: Apps run on Canvas, not in a browser tab. Canvas is your UI window.
Canvas Loading Methods
Canvas has security restrictions that block file path access. Three methods work:
| Method | When to Use | Pros | Cons |
|---|---|---|---|
| Localhost Server | Complex apps, external assets | Full browser features | Requires port management |
| Direct HTML Injection | Quick displays, demos | Instant, no server needed | No external assets, size limit |
| Data URLs | Small content | Self-contained | Unreliable on some systems |
❌ Does NOT work: file:///path/to/file.html (blocked by Canvas security)
📖 See: CANVAS-LOADING.md for detailed guide + troubleshooting
Helper script: canvas-inject.py — Formats HTML for direct injection
1. Apps are HTML/CSS/JS files
~/.openclaw/workspace/apps/[app-name]/
├── index.html # The UI (self-contained recommended)
├── data.json # Persistent state
└── manifest.json # App metadata
2. Serve via localhost
cd ~/.openclaw/workspace/apps/[app-name]
python3 -m http.server [PORT] > /dev/null 2>&1 &
3. Navigate Canvas to localhost
NODE="Your Node Name" # Get from: openclaw nodes status
openclaw nodes canvas navigate --node "$NODE" "http://localhost:[PORT]/"
Important: This opens the app on Canvas (the visual panel), NOT in a browser.
4. Agent injects data via JS eval
openclaw nodes canvas eval --node "$NODE" --js "app.setData({...})"
Note: The openclaw-canvas:// URL scheme has issues in current OpenClaw versions. Use http://localhost: instead.
Opening an App
What this does: Displays the app on Canvas (the visual panel), not in a browser tab.
Method 1: Localhost Server (Recommended for Complex Apps)
Full sequence:
NODE="Your Node Name"
PORT=9876
APP="my-app"
# 1. Kill any existing server on the port
lsof -ti:$PORT | xargs kill -9 2>/dev/null
# 2. Start server
cd ~/.openclaw/workspace/apps/$APP
python3 -m http.server $PORT > /dev/null 2>&1 &
# 3. Wait for server
sleep 1
# 4. Navigate Canvas
openclaw nodes canvas navigate --node "$NODE" "http://localhost:$PORT/"
# 5. Inject data
openclaw nodes canvas eval --node "$NODE" --js "app.loadData({...})"
Method 2: Direct HTML Injection (For Quick Displays)
When to use: File paths don't work in Canvas (security sandboxing). Data URLs can be unreliable. Use this for instant displays without localhost.
# Example using canvas tool
canvas.present(url="about:blank", target=node_name)
html_content = """<!DOCTYPE html>
<html>
<head>
<style>
body { background: #667eea; color: white; padding: 40px; }
.card { background: white; color: #333; padding: 30px; border-radius: 16px; }
</style>
</head>
<body>
<div class="card">
<h1>Your Content Here</h1>
</div>
</body>
</html>"""
# Escape backticks and inject
js_code = f"""document.open();
document.write(`{html_content}`);
document.close();"""
canvas.eval(javaScript=js_code, target=node_name)
Key limitation: File paths (file:///path/to/file.html) are blocked in Canvas for security. Always use localhost or direct injection.
Building Apps
App API Convention
Every app should expose a window.app or window.[appname] object:
window.app = {
// Update values
setValue: (key, val) => {
document.getElementById(key).textContent = val;
},
// Bulk update
loadData: (data) => { /* render all */ },
// Notifications
notify: (msg) => { /* show toast */ }
};
Two-Way Communication
Apps send commands back via deep links:
function sendToAgent(message) {
window.location.href = `openclaw://agent?message=${encodeURIComponent(message)}`;
}
// Button click → agent command
document.getElementById('btn').onclick = () => {
sendToAgent('Refresh my dashboard');
};
Templates
Dashboard
Stats cards, progress bars, lists. Self-contained HTML.
- Default port: 9876
- API:
dashboard.setRevenue(),dashboard.setProgress(),dashboard.notify()
Tracker
Habits/tasks with checkboxes and streaks. Self-contained HTML.
- Default port: 9877
- API:
tracker.setItems(),tracker.addItem(),tracker.toggleItem()
Quick Display (A2UI)
For temporary displays without a full app:
openclaw nodes canvas a2ui push --node "$NODE" --text "
📊 QUICK STATUS
Revenue: \$500
Users: 100
Done!
"
Port Assignments
| App Type | Default Port |
|---|---|
| Dashboard | 9876 |
| Tracker | 9877 |
| Timer | 9878 |
| Display | 9879 |
| Custom | 9880+ |
Design System
:root {
--bg-primary: #0a0a0a;
--bg-card: #1a1a2e;
--accent-green: #00d4aa;
--accent-blue: #4a9eff;
--accent-orange: #f59e0b;
--text-primary: #fff;
--text-muted: #888;
--border: #333;
}
Best Practices
- Self-contained HTML — Inline CSS/JS for portability
- Dark theme — Match OpenClaw aesthetic
- Expose app API — Let agent update via
window.app.* - Use IDs — On elements the agent will update
- Live clock — Shows the app is alive
- Deep links — For two-way communication
Troubleshooting
App opens in browser instead of Canvas?
- Make sure you're using
openclaw nodes canvas navigate, not justopen - Canvas navigate targets the Canvas panel specifically
"Not Found" on Canvas?
- File paths don't work: Canvas blocks
file:///URLs for security (sandboxing) - Data URLs may fail: Use direct HTML injection via
canvas eval+document.write()instead - For localhost: Verify server is running:
curl http://localhost:[PORT]/ - Check port is correct
- Use
http://localhost:notopenclaw-canvas://(URL scheme has issues)
Canvas shows "Not Found" even with correct URL?
- This is a security boundary: Canvas can't access local filesystem
- Solution: Use Method 2 (Direct HTML Injection) from "Opening an App" section
- Or serve via localhost (Method 1)
App not updating?
- Check window.app API is defined:
openclaw nodes canvas eval --js "typeof window.app" - Verify JS eval syntax: single quotes inside double quotes
Server port already in use?
- Kill existing:
lsof -ti:[PORT] | xargs kill -9
Helper Scripts
canvas-inject.py
Python helper for direct HTML injection (Method 2).
# Example usage in Python
from canvas_inject import inject_html_to_canvas
html = open("my-dashboard.html").read()
commands = inject_html_to_canvas(html, node_name="Your Node")
# Then use canvas tool with these commands
canvas.present(**commands["step1_present"])
canvas.eval(**commands["step2_inject"])
Or just follow the pattern manually (see Method 2 in "Opening an App").
Requirements
- OpenClaw with Canvas support (macOS app)
- Python 3 (for http.server)
- A paired node with canvas capability
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。