一键导入
playwright
Browser/data automation via run_playwright_code: tool contract, parallel dispatch, expect() rules, retry strategy classes, and result interpretation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Browser/data automation via run_playwright_code: tool contract, parallel dispatch, expect() rules, retry strategy classes, and result interpretation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | playwright |
| description | Browser/data automation via run_playwright_code: tool contract, parallel dispatch, expect() rules, retry strategy classes, and result interpretation. |
run_playwright_codeOne-shot TypeScript Playwright execution for browser automation and HTTP/API probing.
| Param | Required | Description |
|---|---|---|
code | yes | Complete TS test using @playwright/test |
save_as | no | Base filename, saved as tests/<save_as>.spec.ts |
timeout | no | Max seconds (1..600), default per-call timeout |
| Field | Meaning | Use it for |
|---|---|---|
ok | execution_ok && data_ok | Quick "did the whole thing work" check |
execution_ok | Process exited 0 | Was there a crash? |
data_ok | No data-failure warnings | Did we actually get useful data? |
warnings | Machine-readable caveats | What went wrong (HTTP error, empty results, JSON parse, etc.) |
exit_code, stdout, stderr | Raw process output | Debugging |
timed_out | Hit timeout | Retry with larger timeout or different source |
setup_error | Runtime broken | Stop — do not retry; report to user |
execution_ok=true but data_ok=false. The process ran but returned nothing useful.warnings before responding. Common blockers:
http_4xx_or_5xx_detected → endpoint failedjson_parse_failure_detected → response wasn't JSONempty_collection_detected / no_results_detected → 0 resultsassertion_received_false → an expect() failedsetup_error=true → stop and report. Do NOT retry; the runtime is broken.Before writing TS code, answer:
What kind of source?
request fixture (Class A — fast, no JS)page fixture (Class B)Does this need parallel calls?
Is 0 results a valid outcome?
expect() on countsexpect()Multiple run_playwright_code calls without inter-dependencies must be issued in the same response. This is the single biggest budget multiplier.
| Scenario | Action |
|---|---|
| Shotgun search across sources | All run_playwright_code calls in one response |
| Read multiple articles (URLs known) | All reads in one response |
| API + page scrape, same topic | Both in one response |
| Search + known static endpoint (e.g. Wikipedia API) | Both in one response |
| Scenario | Why |
|---|---|
| Article read using URL from prior search | URL not known until search returns |
| Test B's code contains a placeholder filled from A's stdout | Hard data dependency |
Multi-step API flows (fetch IDs → fetch details with those IDs) belong inside a single run_playwright_code test using sequential await calls.
request for machine-readable sourcesJSON, RSS, XML APIs are faster and more reliable via request than via page.
expect() Usage RuleUse expect() when failure = hard error:
body.items must be an array)Do NOT use expect() when 0/empty is a valid outcome:
results.length > 0 will crash on empty searches)A failed expect() crashes the test → execution_ok=false → masks the real "source returned nothing" signal.
Downstream reasoning uses stdout parsing. Format:
console.log(JSON.stringify({ source: 'name', count: results.length, results }, null, 2));
expect())import { test, expect } from '@playwright/test';
test('fetch API', async ({ request }) => {
const res = await request.get('https://example.com/api/items', { timeout: 15000 });
expect(res.ok()).toBeTruthy(); // 2xx is mandatory
const body = await res.json();
expect(Array.isArray(body.items)).toBeTruthy(); // schema check
// NO expect on body.items.length — 0 results is valid
console.log(JSON.stringify({ source: 'api', count: body.items.length, items: body.items.slice(0, 5) }, null, 2));
});
import { test } from '@playwright/test';
test('search', async ({ page }) => {
await page.goto('https://example.com/search?q=TOPIC', { waitUntil: 'domcontentloaded', timeout: 20000 });
await page.waitForSelector('.result', { timeout: 10000 }).catch(() => {});
const results = await page.$$eval('.result', els => els.slice(0, 10).map(el => ({
title: el.querySelector('h2')?.textContent?.trim() || '',
url: el.querySelector('a')?.getAttribute('href') || ''
})).filter(r => r.title && r.url));
console.log(JSON.stringify({ source: 'example', count: results.length, results }, null, 2));
});
When a class fails, switch class — never retry the same class with tweaked args.
| Class | Use when | Switch to on failure |
|---|---|---|
A — request | JSON/RSS/API, fast, no JS needed | B (page) or C (alternative source) |
B — page | Rendered UI, JS-heavy, dynamic content | A (find an API endpoint) or C |
| C — alternative source | Same data, different provider | Stop, report best-effort |
setup_error → stop immediately, report runtime issue.Before delivering an answer based on a tool result:
setup_error is falsetimed_out is falseexecution_ok is truedata_ok is truewarnings has no blocking entries (http_4xx_or_5xx_detected, assertion_received_false, no_results_detected, etc.)stdout content is on-topic — not a CAPTCHA page, bot-detection interstitial, redirect loop, or foreign-language fallback. A CAPTCHA page can still set data_ok=true if stdout is non-empty — check the actual content.If any item fails, retrieval is incomplete. Report it and switch class/source per retry rules above.
[tool output cleared]), re-run the tool — do not infer missing values.large_tool_results/, re-read with read_file(path, offset, limit).| Symptom | Likely cause | Fix |
|---|---|---|
data_ok=false, no_results_detected | Search returned nothing | Switch source, NOT same source with tweaks |
execution_ok=false, assertion_received_false | Bad expect() on count | Remove the count assertion |
timed_out=true | Page slow / blocked | Try request fixture or different source |
http_4xx_or_5xx_detected | API rejected | Wrong endpoint, missing auth, or rate-limited — switch source |
| Stdout has CAPTCHA HTML | Bot detection | Switch to API or different engine (see websearch skill) |
Cross-cutting operating rules for Travis-2: pre-flight gates, parallel execution, bounded budgets, todo discipline, retry/fallback policy, and response quality.
Hard-coded Playwright recipes for web research: engine rules, domain routing, parallel shotgun pattern, 3-call budget, and citation discipline.