Usage
The skill triggers on any message that contains Chrome, browser, Selenium, screenshot, or open.
CODEBLOCK0
Command flow
- 1. Launch Chrome (or Chromium) under Selenium.
- Navigate to
<URL>. - Take a screenshot of the loaded page.
- Save the image in
/home/main/clawd/diffusion_pdfs/ and report the path back to the chat. - If anything fails, send an error message.
Scripts
scripts/launch_browser.py
CODEBLOCK1
scripts/_env.sh
CODEBLOCK2
References
How the skill reports
The skill runs the Python script and captures its stdout as a JSON payload. OpenClaw parses the JSON and sends a message back:
CODEBLOCK3
If the script prints an error, the skill forwards the error text.
Installation notes
- 1. Make sure
chromedriver is in /usr/local/bin/chromedriver or set CHROMEDRIVER_PATH. - Make sure
google-chrome (or chromium) is in /usr/bin/google-chrome or set CHROME_BIN. - Install Python dependencies:
pip install selenium (inside the virtual env you use for the skill).
CODEBLOCK4
Logging & timeouts
The script uses a 5‑second static wait after navigation; replace with Selenium's
WebDriverWait for dynamic waits.
If you encounter timeouts, adjust the time.sleep(5) value or use WebDriverWait(driver, 20).until(...).
Feel free to tweak the script to fit your environment (proxy, authentication, etc.).
```
用法
该技能会触发于任何包含 Chrome、浏览器、Selenium、截图 或 打开 的消息。
bash
selenium-browser [--headless] [--proxy=]
命令流程
- 1. 启动 基于 Selenium 的 Chrome(或 Chromium)浏览器。
- 导航 至 。
- 截取 已加载页面的屏幕截图。
- 保存 图片至 /home/main/clawd/diffusion_pdfs/ 目录,并报告路径回聊天窗口。
- 若任何步骤失败,则发送错误信息。
脚本
scripts/launch_browser.py
python
#!/usr/bin/env python3
import os
import sys
import time
import base64
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
CLI 解析
import argparse
parser = argparse.ArgumentParser(description=启动 Selenium Chrome 并截取屏幕截图。)
parser.add_argument(url, help=要打开的 URL)
parser.add
argument(--headless, action=storetrue, help=以无头模式运行 Chrome)
parser.add_argument(--proxy, help=代理 URL(例如 http://proxy:3128))
args = parser.parse_args()
准备 Chrome 选项
chrome_options = Options()
if args.headless:
chrome
options.addargument(--headless)
chrome
options.addargument(--disable-gpu)
chrome
options.addargument(--no-sandbox)
chrome
options.addargument(--disable-dev-shm-usage)
if args.proxy:
chrome
options.addargument(f--proxy-server={args.proxy})
定位二进制文件
chrome
bin = os.getenv(CHROMEBIN, /usr/bin/google-chrome)
chromedriver
path = os.getenv(CHROMEDRIVERPATH, /usr/local/bin/chromedriver)
service = Service(executablepath=chromedriverpath)
启动浏览器
try:
driver = webdriver.Chrome(service=service, options=chrome_options)
except Exception as e:
print(f❌ 启动 Chrome 失败:{e}, file=sys.stderr)
sys.exit(1)
导航并等待页面加载
try:
driver.get(args.url)
time.sleep(5) # 简单等待;可替换为 WebDriverWait 以获得更好的可靠性
except Exception as e:
print(f❌ 导航错误:{e}, file=sys.stderr)
driver.quit()
sys.exit(1)
截取屏幕截图
screenshot_path = os.path.join(os.getenv(HOME, /tmp), screenshot.png)
try:
driver.save
screenshot(screenshotpath)
except Exception as e:
print(f❌ 截图错误:{e}, file=sys.stderr)
driver.quit()
sys.exit(1)
清理
driver.quit()
输出 OpenClaw 可解析的 JSON 对象以用于回复
print({status: ok, screenshot: screenshot_path})
scripts/_env.sh
bash
可选:如果 Chrome/Chromedriver 不在标准位置,设置其路径
export CHROME_BIN=/opt/google/chrome/google-chrome
export CHROMEDRIVER_PATH=/usr/local/bin/chromedriver
参考资料
技能报告方式
该技能运行 Python 脚本并将其标准输出捕获为 JSON 负载。OpenClaw 解析该 JSON 并发送回消息:
✅ 截图已保存:/home/main/clawd/diffusion_pdfs/screenshot.png
如果脚本输出错误信息,该技能会转发错误文本。
安装说明
- 1. 确保 chromedriver 位于 /usr/local/bin/chromedriver 或设置 CHROMEDRIVERPATH 环境变量。
- 确保 google-chrome(或 chromium)位于 /usr/bin/google-chrome 或设置 CHROMEBIN 环境变量。
- 安装 Python 依赖:pip install selenium(在您用于该技能的虚拟环境中执行)。
bash
pip install selenium
日志与超时
该脚本在导航后使用 5 秒静态等待;可替换为 Selenium 的 WebDriverWait 以实现动态等待。
如果遇到超时问题,请调整 time.sleep(5) 的值或使用 WebDriverWait(driver, 20).until(...)。
欢迎根据您的环境(代理、认证等)调整脚本。