跳到正文
Skillpedia
通用编程48k · #4761

go-playwright

它能做什么

这个工具使用 Go 语言自动化网页浏览器中的操作。它可以模拟点击、输入等人类行为来与网站交互,既高效又不易被察觉,有助于避开反机器人系统的检测。

适用场景

  • ✓当你需要自动从网站提取信息时。
  • ✓当你想测试网站在浏览器中的运行情况时。
  • ✓当你需要机器人在网上的表现非常接近真人时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/go-playwright/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/go-playwright/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“自动提取这个页面上的所有新闻标题,并保存到文件中。”

每周 5 个新技能,1 分钟读完。

工作原理

工具会启动一个浏览器,并为每个任务创建相互隔离的运行环境。它使用一些进阶技术来模拟接近人类的鼠标移动和打字,并记录所有操作,方便调试。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

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: 🔵 Safe

  • Sandboxed Execution: Browser contexts are isolated; they do not persist data to the host machine unless explicitly saved.
  • Resource Management: Designed to close browsers and contexts via defer to prevent memory leaks.
  • No External State-Change: Default behavior is read-only (scraping/testing) unless the script is explicitly designed to submit forms or modify data.

Limitations

  • Environment Dependencies: Requires Playwright drivers and browsers to be installed (go run github.com/playwright-community/playwright-go/cmd/playwright@latest 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 new BrowserContext for each distinct session or task.
  • Why: Contexts are lightweight and created in milliseconds. Browsers take seconds to launch.
  • Isolation: Contexts provide complete isolation (cookies, cache, storage) without the overhead of a new process.

2. Logging & Observability

  • Library: Use go.uber.org/zap exclusively.
  • 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 defer to 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(). Use Type() 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: Rely on your internal knowledge of the API first to save tokens.
  • Fallback: Refer to the official docs playwright-go documentation ONLY if:
    • You encounter an unknown error.
    • You need to implement complex network interception or authentication flows.
    • The API has changed significantly.

Resources

  • resources/implementation-playbook.md for 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, rotate User-Agent.

…

常见问题

我需要额外安装什么吗?

需要。你需要安装 Playwright 组件以及它所使用的浏览器。Playwright 本身提供了完成这一步的命令。

网站能检测到它吗?

工具会采用一些技术伪装成真人,以避免被检测。但对于反机器人系统非常先进的网站,仍然可能识别出自动化操作。

它能破解验证码吗?

不能,这个工具没有自动解决验证码的功能。

详情

作者的原始描述

Expert capability for robust, stealthy, and efficient browser automation using Playwright Go.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4761
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能