首页龙虾技能列表 › Playwright CLI — Playwright 命令行

Playwright CLI — Playwright 命令行

v1.0.0

Playwright 命令行自动化工具。

3· 1,705·10 当前·10 累计
by @michael-c-matias (Michael-C-Matias)·MIT-0
下载技能包
License
MIT-0
最后更新
2026/3/12
安全扫描
VirusTotal
无害
查看报告
OpenClaw
安全
high confidence
The skill is an instruction-only Playwright CLI guide whose requested actions and examples match its stated purpose; nothing in the bundle is disproportionate or clearly malicious, but exercise normal caution when installing packages and handling credentials.
评估建议
This skill is a plain instruction guide for using Playwright CLI and appears coherent with that purpose. Before using it: (1) verify Playwright is installed from official npm/pypi sources and run installs in a controlled environment; (2) inspect any generated scripts (codegen output) before executing; (3) avoid hard-coding real credentials — use secure secret storage or ephemeral test accounts; (4) treat saved storage files (auth.json) as sensitive; and (5) note the skill bundle has no homepage ...
详细分析 ▾
用途与能力
The name/description claim this is the Microsoft Playwright CLI and the SKILL.md provides installation commands and CLI usage that align with that purpose. However the skill bundle has no source/homepage and is instruction-only (no code or official links), so the package is a documentation/instruction wrapper rather than an officially published Playwright artifact — this is plausible but reduces provenance/trust.
指令范围
The instructions stay within the expected scope (install Playwright, install browsers, run screenshots, codegen, tests, and examples). They include examples that automate logins and suggest saving/loading storage files (auth.json) and embedding username/password placeholders — these are expected for browser automation but involve handling sensitive credentials and session files, so users should avoid storing secrets in plain files or run such scripts without review.
安装机制
There is no install spec in the skill itself (instruction-only). The SKILL.md recommends standard install commands (npm install -g @playwright/test or pip install playwright and running playwright install) which are normal for Playwright. Note that those commands will download third-party code from public package registries; review and run them in a trusted environment.
凭证需求
The skill declares no required environment variables, credentials, or config paths. The examples reference usernames/passwords and storage files but do not require any undeclared secrets. This is proportionate to a browser automation guide, but users should avoid embedding real secrets in scripts or saving auth JSON files without protection.
持久化与权限
The skill does not request persistent presence (always is false), does not modify other skills or system-wide settings, and contains no install-time hooks. It only provides runtime instructions for the agent to follow when invoked.
安全有层次,运行前请审查代码。

License

MIT-0

可自由使用、修改和再分发,无需署名。

运行时依赖

无特殊依赖

版本

latestv1.0.02026/3/12

Initial release, support full Microsoft Playwright CLI web automation operations, including page navigation, element interaction, screenshot, PDF generation, operation recording and other functions

● 无害

安装命令 点击复制

官方npx clawhub@latest install playwright-cli-openclaw
镜像加速npx clawhub@latest install playwright-cli-openclaw --registry https://cn.clawhub-mirror.com

技能文档

Playwright CLI是微软官方的浏览器自动化工具,支持Chromium、Firefox、WebKit三大主流浏览器,提供强大的网页自动化能力。

安装步骤

1. 安装Playwright CLI

npm install -g @playwright/test
# 或者
pip install playwright

2. 安装浏览器

playwright install
# 仅安装特定浏览器
playwright install chromium firefox
# 安装系统依赖(Linux环境)
playwright install-deps

核心常用命令

页面操作

# 打开指定网页
playwright open https://example.com

# 无头模式打开网页并截图 playwright screenshot https://example.com example.png # 全屏截图 playwright screenshot https://example.com --full-page full.png # 指定视口大小 playwright screenshot https://example.com --viewport-size=1920,1080 desktop.png

# 生成PDF playwright pdf https://example.com example.pdf # 自定义PDF格式 playwright pdf https://example.com --format=A4 --landscape report.pdf

录制用户操作

# 录制用户操作并生成代码
playwright codegen https://example.com
# 保存录制结果到文件
playwright codegen https://example.com --output script.py
# 生成指定语言的代码(python, javascript, java, csharp)
playwright codegen https://example.com --target python

测试相关

# 运行测试
playwright test
# 运行特定测试文件
playwright test tests/example.spec.js
# 有头模式运行测试(显示浏览器界面)
playwright test --headed
# 调试模式运行
playwright test --debug
# 生成测试报告
playwright show-report

浏览器管理

# 列出已安装的浏览器
playwright list-browsers
# 更新浏览器到最新版本
playwright install --force
# 卸载浏览器
playwright uninstall chromium

使用示例

示例1:批量截图多个网页

# 对多个网页进行全屏截图
for url in "https://google.com" "https://github.com" "https://stackoverflow.com"; do
  name=$(echo $url | sed 's/https\?:\/\///' | sed 's/\//_/g')
  playwright screenshot $url --full-page "${name}.png"
done

示例2:自动填写表单

# 录制生成的自动登录脚本示例
from playwright.sync_api import Playwright, sync_playwright, expect

def run(playwright: Playwright) -> None: browser = playwright.chromium.launch(headless=False) context = browser.new_context() page = context.new_page() page.goto("https://example.com/login") page.get_by_label("用户名").fill("your_username") page.get_by_label("密码").fill("your_password") page.get_by_role("button", name="登录").click() # 截图登录后的页面 page.screenshot(path="logged_in.png") context.close() browser.close()

with sync_playwright() as playwright: run(playwright)

示例3:模拟移动端访问

# 模拟iPhone 14访问网页并截图
playwright screenshot https://example.com --device="iPhone 14" mobile.png
# 模拟安卓设备
playwright screenshot https://example.com --device="Galaxy S23" android.png

最佳实践

  • 优先使用无头模式执行自动化任务,性能更高
  • 复杂操作优先使用codegen录制生成代码,再手动调整
  • 执行长时间任务时添加--slowmo=1000参数减慢操作速度,避免被反爬
  • 保存登录状态使用--保存-storage=auth.json,下次可以直接--加载-storage=auth.json跳过登录
  • 网络不稳定时添加--超时=60000延长超时时间
数据来源:ClawHub ↗ · 中文优化:龙虾技能库
OpenClaw 技能定制 / 插件定制 / 私有工作流定制

免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制

了解定制服务