← 返回 Skills 市场
Playwright (scripts) + npx
作者
mahone-bot
· GitHub ↗
· v1.0.0
1760
总下载
0
收藏
18
当前安装
1
版本数
在 OpenClaw 中安装
/install playwright-npx
功能描述
Run Node.js scripts using Playwright for full browser automation, including scraping, screenshots, form handling, and dynamic content interaction.
使用说明 (SKILL.md)
Playwright Browser Automation
🤝 Developed together by Kuba + Mahone · Feb 2026
Code-first browser automation with Playwright.
When to Use
| Tool | Use When |
|---|---|
| web_fetch | Simple pages, no JavaScript needed |
| This skill | JavaScript-heavy sites, complex interactions, full control |
| stealth-browser | Bot detection / Cloudflare issues |
| browser tool | Visual exploration, last resort |
| playwright-cli | Interactive CLI without writing code |
Setup
# One-time per project
npm init -y
npm install playwright
npx playwright install chromium
package.json example:
{
"name": "my-automation",
"type": "module",
"dependencies": {
"playwright": "^1.40.0"
}
}
Minimal Example
// tmp/example.mjs
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
console.log('Title:', await page.title());
await browser.close();
node tmp/example.mjs
Quick Patterns
Screenshot
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.setViewportSize({ width: 1280, height: 800 });
await page.goto('https://example.com');
await page.screenshot({ path: 'tmp/screenshot.png', fullPage: true });
await browser.close();
Scrape Data
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com');
const stories = await page.$$eval('.titleline > a', links =>
links.slice(0, 5).map(a => ({ title: a.innerText, url: a.href }))
);
console.log(JSON.stringify(stories, null, 2));
await browser.close();
Form Interaction
await page.goto('https://example.com/login');
await page.fill('input[name="email"]', '[email protected]');
await page.fill('input[name="password"]', 'password');
await page.click('button[type="submit"]');
Wait for Dynamic Content
// Wait for network idle (SPA)
await page.goto(url, { waitUntil: 'networkidle' });
// Wait for specific element
await page.waitForSelector('.results', { timeout: 10000 });
// Wait for condition
await page.waitForFunction(() =>
document.querySelectorAll('.item').length > 0
);
Persistent Session
import fs from 'fs';
const SESSION_FILE = 'tmp/session.json';
let context;
if (fs.existsSync(SESSION_FILE)) {
context = await browser.newContext({ storageState: SESSION_FILE });
} else {
context = await browser.newContext();
}
const page = await context.newPage();
// ... login ...
await context.storageState({ path: SESSION_FILE });
Headless vs Headed
// Headless (default, fastest)
await chromium.launch({ headless: true });
// Headed (see the browser)
await chromium.launch({ headless: false });
// Slow motion (debugging)
await chromium.launch({ headless: false, slowMo: 100 });
Selectors Quick Reference
// CSS
await page.click('button.submit');
await page.fill('input#email', 'text');
// Text content
await page.click('text=Submit');
await page.click('text=/log\s*in/i'); // regex
// XPath
await page.click('xpath=//button[@type="submit"]');
// ARIA role
await page.click('role=button[name="Submit"]');
// Test ID (most stable)
await page.click('[data-testid="submit-btn"]');
// Chain selectors
await page.click('nav >> text=Settings');
See references/selectors.md for complete selector guide.
Error Handling
try {
await page.goto('https://example.com', { timeout: 30000 });
const hasResults = await page.locator('.results').isVisible().catch(() => false);
if (!hasResults) {
console.log('No results');
process.exit(0);
}
} catch (error) {
console.error('Error:', error.message);
await page.screenshot({ path: 'tmp/error.png' });
process.exit(1);
} finally {
await browser.close();
}
Examples & Templates
Working Examples
- examples/screenshot.mjs - Full-page screenshots
- examples/scrape.mjs - Data extraction
- examples/form-interaction.mjs - Form automation
- examples/login-session.mjs - Persistent sessions
Reusable Templates
- scripts/minimal-template.mjs - Clean starting point
- scripts/screenshot-template.mjs - Configurable screenshot
- scripts/scrape-template.mjs - Data scraping scaffold
Copy templates:
cp scripts/minimal-template.mjs tmp/my-task.mjs
# Edit tmp/my-task.mjs, then run:
node tmp/my-task.mjs
Tooling Commands
# Record interactions to generate code
npx playwright codegen https://example.com
# Debug selectors
npx playwright codegen --target javascript https://example.com
# Show trace
npx playwright show-trace tmp/trace.zip
Deep References
- references/selectors.md - Complete selector guide (CSS, text, XPath, ARIA, test-id)
- references/debugging.md - Debugging techniques (headless, slowMo, screenshots)
- references/troubleshooting.md - Common errors and solutions
Tips
- Always put scripts in
tmp/— it's gitignored - Use
.mjsextension for ES modules (notype: moduleneeded) - Add
console.log()liberally for debugging - Use
page.screenshot()when things go wrong - For complex sites, add
await page.waitForLoadState('networkidle') - See references/debugging.md for detailed debugging guide
- See references/troubleshooting.md for common issues
安全使用建议
This skill appears to do what it says (run Playwright scripts) but it executes arbitrary Node code that can hit any website and read/write local files. Before using: (1) review the included example scripts and any script you run; (2) avoid running untrusted scripts or code from unknown authors; (3) be cautious about session files (tmp/session.json) — they can contain cookies/tokens; (4) run installs (npm install / npx playwright install) in an isolated project or container, pin the playwright version, and run npm audit; (5) if you need to limit risk, run scripts in a sandboxed environment (VM/container) or restrict network/file access. If you want, inspect the GitHub repo referenced in _meta.json before installing or using.
功能分析
Type: OpenClaw Skill
Name: playwright-npx
Version: 1.0.0
The OpenClaw AgentSkills bundle provides comprehensive tools and documentation for browser automation using Playwright. All code examples and instructions are aligned with the stated purpose of web scraping, screenshots, and form automation. File system access (e.g., `fs.writeFileSync`, `fs.existsSync`) is used legitimately for saving session states and screenshots to local `tmp/` directories. Network access is inherent to browser automation and is directed towards legitimate demonstration sites. There is no evidence of data exfiltration, unauthorized command execution, persistence mechanisms, obfuscation, or prompt injection attempts against the AI agent in any of the files.
能力评估
Purpose & Capability
Name/description (Playwright via node/npx) align with requirements and files. Required binaries (node, npx) and the examples/templates/scripts all directly support browser automation, scraping, screenshots and form automation; nothing requested is unrelated to that purpose.
Instruction Scope
SKILL.md and example scripts instruct the agent/user to run npm install, npx playwright install, and node .mjs scripts that navigate arbitrary websites, take screenshots, and read/write local files (e.g., tmp/session.json, tmp/*.png). This is expected for Playwright but means the skill executes code with filesystem and network access; session persistence may store cookies/auth tokens and examples show file upload APIs (setInputFiles). Users should be aware these are sensitive capabilities.
Install Mechanism
No automated install spec in the skill bundle (instruction-only). The docs recommend standard npm + npx commands (npm install playwright, npx playwright install) which pull packages/binaries from npm/Playwright distribution — expected for this tooling and not an untrusted arbitrary-download pattern.
Credentials
The skill declares no environment variables or credentials (proportionate). However, example code persists storageState/session files and demonstrates proxy configuration examples that could include credentials; these are examples rather than required env vars, but they highlight that scripts can store or transmit sensitive data if misused.
Persistence & Privilege
Skill does not request always:true and does not modify other skills or global agent config. It is user-invocable and can run code when invoked, which is appropriate for its purpose.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install playwright-npx - 安装完成后,直接呼叫该 Skill 的名称或使用
/playwright-npx触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of playwright-npx: Fast Node.js scripting for browser automation with Playwright.
- Provides usage guide for browser tasks: scraping, screenshots, form automation, and custom workflows.
- Includes quick setup, minimal script examples, and patterns for screenshots, scraping, form automation, and dynamic content handling.
- Documents persistent session techniques, headless/headed debugging, and selector strategies.
- Lists working script templates and example files for rapid development.
- Offers troubleshooting, debugging, and selector reference links for deeper guidance.
元数据
常见问题
Playwright (scripts) + npx 是什么?
Run Node.js scripts using Playwright for full browser automation, including scraping, screenshots, form handling, and dynamic content interaction. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1760 次。
如何安装 Playwright (scripts) + npx?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install playwright-npx」即可一键安装,无需额外配置。
Playwright (scripts) + npx 是免费的吗?
是的,Playwright (scripts) + npx 完全免费(开源免费),可自由下载、安装和使用。
Playwright (scripts) + npx 支持哪些平台?
Playwright (scripts) + npx 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Playwright (scripts) + npx?
由 mahone-bot(@mahone-bot)开发并维护,当前版本 v1.0.0。
推荐 Skills