首页龙虾技能列表 › Playwright npx — Playwright 脚本

🎭 Playwright npx — Playwright 脚本

v1.0.0

Playwright 脚本工具,支持 npx 运行。

0· 1,602·18 当前·18 累计
by @mahone-bot·MIT-0
下载技能包
License
MIT-0
最后更新
2026/2/26
安全扫描
VirusTotal
无害
查看报告
OpenClaw
安全
medium confidence
This skill is internally consistent with its stated purpose (running Playwright Node scripts); the required tools and included examples match the description, but users should be aware it runs arbitrary scripts that access the network and local files (including session/cookie files).
评估建议
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 ve...
详细分析 ▾
用途与能力
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.
指令范围
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.
安装机制
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.
凭证需求
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.
持久化与权限
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.
安全有层次,运行前请审查代码。

License

MIT-0

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

运行时依赖

无特殊依赖

版本

latestv1.0.02026/2/14

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.

● 无害

安装命令 点击复制

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

技能文档

🤝 Developed together by Kuba + Mahone · Feb 2026

Code-first browser automation with Playwright.

当...时 到 使用

ToolUse When
web_fetchSimple pages, no JavaScript needed
This skillJavaScript-heavy sites, complex interactions, full control
stealth-browserBot detection / Cloudflare issues
browser toolVisual exploration, last resort
playwright-cliInteractive CLI without writing code

Setup

# One-time per project
npm init -y
npm install playwright
npx playwright install chromium

包.json 示例:

{
  "name": "my-automation",
  "type": "module",
  "dependencies": {
    "playwright": "^1.40.0"
  }
}

Minimal 示例

// 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();

表单 Interaction

await page.goto('https://example.com/login');
await page.fill('input[name="email"]', 'user@example.com');
await page.fill('input[name="password"]', 'password');
await page.click('button[type="submit"]');

Wait 对于 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 会话

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 对于 complete selector guide.

错误 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

Reusable Templates

复制 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

Tips

  • Always put scripts 在...中 tmp/ — 's gitignored
  • 使用 .mjs 扩展 对于 ES modules (否 类型: 模块 needed)
  • 添加 console.log() liberally 对于 debugging
  • 使用 page.screenshot() 当...时 things go wrong
  • 对于 complex sites, 添加 等待 page.waitForLoadState('networkidle')
  • See references/debugging.md 对于 detailed debugging guide
  • See references/troubleshooting.md 对于 common issues
数据来源:ClawHub ↗ · 中文优化:龙虾技能库
OpenClaw 技能定制 / 插件定制 / 私有工作流定制

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

了解定制服务