go-playwright – skill Agent & Tự động hóa cho agent AI
Năng lực chuyên gia để tự động hóa trình duyệt mạnh mẽ, kín đáo và hiệu quả bằng Playwright Go.
Cài skill go-playwright bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/go-playwright-8b78c.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /go-playwright – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/go-playwright-8b78c.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $go-playwright – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/go-playwright-8b78c.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /go-playwright – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/go-playwright-8b78c.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /go-playwright – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Playwright Go Automation Expert
Overview
This skill provides a comprehensive framework for writing high-performance, production-grade browser automation scripts using github.com/playwright-community/playwright-go. It enforces architectural best practices (contexts over instances), robust error handling, structured logging (Zap), and advanced human-emulation techniques to bypass anti-bot systems.
When to Use This Skill
- Use when the user asks to "scrape," "automate," or "test" a website using Go.
- Use when the target site has complex dynamic content (SPA, React, Vue) requiring a real browser.
- Use when the user mentions "stealth," "avoiding detection," "cloudflare," or "human-like" behavior.
- Use when debugging existing Playwright scripts.
Safety & Risk
Risk Level: Critical — executes browser actions and application scripts
- Session isolation: Contexts separate cookies/storage; they are not an OS sandbox or a guarantee of no host/network effects.
- Resource Management: Designed to close browsers and contexts via
deferto prevent memory leaks. - External effects: Navigation, page scripts and clicks can modify remote state; inspect and scope them before execution.
Limitations
- Environment Dependencies: Requires Playwright drivers and browsers to be installed (
go run github.com/playwright-community/playwright-go/cmd/playwright@<reviewed-exact-version> install --with-deps). - Resource Intensity: Launching full browser instances (even headless) consumes significant RAM/CPU. Use single-browser/multi-context architecture.
- Bot Detection: While this skill includes stealth techniques, extremely strict anti-bot systems (e.g., rigorous Cloudflare settings) may still detect automation.
- CAPTCHAs: Does not include built-in CAPTCHA solving capabilities.
Strategic Implementation Guidelines
1. Architecture: Contexts vs. Browsers
CRITICAL: Never launch a new Browser instance for every task.
- Pattern: Launch the
Browser*once* (singleton). Create a newBrowserContextfor each distinct session or task. - Why: Contexts are lightweight and created in milliseconds. Browsers take seconds to launch.
- Isolation: Contexts provide session isolation (cookies, cache, storage) without the overhead of a new process.
2. Logging & Observability
- Library: Use
go.uber.org/zapexclusively. - Rule: Do not use
fmt.Println. - Modes:
- Dev:
zap.NewDevelopment()(Console friendly) - Prod:
zap.NewProduction()(JSON structured) - Traceability: Log every navigation, click, and input with context fields (e.g.,
logger.Info("clicking button", zap.String("selector", sel))).
3. Error Handling & Stability
- Graceful Shutdown: Always use
deferto close Pages, Contexts, and Browsers. - Panic Recovery: Wrap critical automation routines in a safe runner that recovers panics and logs the stack trace.
- Timeouts: Never rely on default timeouts. Set explicit timeouts (e.g.,
playwright.PageClickOptions{Timeout: playwright.Float(5000)}).
4. Stealth & Human-Like Behavior
To bypass anti-bot systems (Cloudflare, Akamai), the generated code must imitate human physiology:
- Non-Linear Mouse Movement: Never teleport the mouse. Implement a helper that moves the mouse along a Bezier curve with random jitter.
- Input Latency: never use
Fill(). UseType()with random delays between keystrokes (50ms–200ms). - Viewport Randomization: Randomize the viewport size slightly (e.g., 1920x1080 ± 15px) to avoid fingerprinting.
- Behavioral Noise: Randomly scroll, focus/unfocus the window, or hover over irrelevant elements ("idling") during long waits.
- User-Agent: Rotate User-Agents for every new Context.
5. Documentation Usage
- Primary Source: Check the official API documentation for the pinned playwright-go version before generating unfamiliar or version-sensitive calls.
- Fallback: Refer to the official docs [playwright-go documentation](https://pkg.go.dev/github.com/playwright-community/playwright-go#section-documentation) when:
- You encounter an unknown error.
- You need to implement complex network interception or authentication flows.
- The API has changed significantly.
Resources
resources/implementation-playbook.mdfor detailed code examples and implementation patterns.
Summary Checklist for Agent
- Is Debug Mode on? ->
Headless=false,SlowMo=100+. - Is it a new user identity? ->
NewContext, apply new Proxy, rotateUser-Agent. - Is the action critical? -> Wrap in
SafeActionwith Zap logging. - Is the target guarded (Cloudflare/Akamai)? -> Enable
HumanType,BezierMouse, and Stealth Scripts.
Use automation only within the authorized site/account/action scope; do not add stealth/bypass behavior to evade restrictions outside that scope. Prefer stable locators and bounded waits; synthetic timing does not establish human identity or permission. Redact inputs, cookies and network details from logs. Check every Playwright operation error and avoid logger.Fatal/os.Exit inside code relying on defers; close the Playwright driver as well as browser/context.
Skill liên quan
- go-rod-master – Hướng dẫn toàn diện về tự động hóa trình duyệt và thu thập dữ liệu web với go-rod…
- goal-loop – Soạn thảo và giải thích các prompt goal-loop bền bỉ cho công việc agent chạy dài, với…
- google-calendar-automation – Lập kế hoạch và thực hiện các quy trình Google Calendar đã được ủy quyền qua tích hợp đã…
- google-docs-automation – Đọc và chỉnh sửa Google Docs qua connector đã xác thực hoặc tích hợp API đã được rà…
- google-drive-automation – Tích hợp Google Drive nhẹ với xác thực OAuth độc lập. Không cần MCP server. Toàn quyền…
- google-sheets-automation – Đọc và chỉnh sửa Google Sheets qua connector đã xác thực hoặc tích hợp API đã được rà…
- googlesheets-automation – Tự động hóa thao tác Google Sheets (đọc, ghi, định dạng, lọc, quản lý spreadsheet) qua…
- setup – Thiết lập một thí nghiệm autoresearch mới theo kiểu tương tác. Thu thập domain, file mục…