微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🤖

零Token自动化,人机行为反检测

Browser Automation Ultra · v1.0.0
效率 安全 A 级 作者 swaylq 公开目录收录
1.2k 下载 0 安装 5.4k 收藏 30 浏览

简介

通过Playwright脚本实现零Token浏览器自动化,支持CDP锁管理与人机交互模拟,用于工作流自动化、反检测爬取与多平台发布

原始描述

Zero-token browser automation via Playwright scripts with CDP lock management and human-like interaction. Use when: (1) automating any browser-based workflow...

通过你的 Agent 添加

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/browser-automation-ultra/
Codex CLI~/.codex/skills/browser-automation-ultra/
DeepSeek Harness~/.agents/skills/browser-automation-ultra/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

Browser Automation Ultra 提供了一套完整的浏览器自动化解决方案,采用「探索→记录→回放→修复」的工作流:

  1. 探索阶段:使用 OpenClaw 内置的 browser 工具(消耗 Token)分析目标网站,记录页面结构、选择器和操作流程
  2. 记录阶段:将探索结果转换为 Playwright 脚本,保存至 scripts/browser/<verb>-<target>.js,强制使用 human-like.js 实现人机模拟行为
  3. 回放阶段:通过 ./scripts/browser-lock.sh run 以零 Token 成本执行脚本,复用已登录的 Chrome 会话
  4. 修复阶段:出错时重新用 browser 工具检查实际页面状态,而非盲目猜测修复

关键技术架构:通过 Chrome DevTools Protocol (CDP) 连接 OpenClaw 的现有 Chrome 实例,共享 Cookies 和登录状态。browser-lock.sh 管理互斥锁,确保 OpenClaw browser 工具与 Playwright 脚本不会同时抢占 CDP 端口。

显著优点

  • 零 Token 执行:一次性探索后,后续无数次回放均为免费
  • 状态复用:直接继承 OpenClaw 浏览器的登录态,无需重复认证
  • 反检测能力:内置 human-like.js 强制要求,包括贝塞尔曲线鼠标移动、随机延时、逐字符输入(3% 模拟 typo 率)、页面浏览模拟等,有效对抗主流 bot 检测
  • 生产就绪:提供 DeviantArt、小红书、Pinterest、Behance、Proton Mail 等平台的实测脚本模板
  • CDP 冲突解决:通过锁机制彻底解决 OpenClaw browser 与 Playwright 的端口争用问题

潜在缺点与局限性

  • 架构复杂度高:需理解 CDP、互斥锁、Playwright 三者的交互关系,调试门槛较高
  • 单会话限制:同一时刻仅能有一个 CDP 客户端连接,并发场景需排队或另起浏览器实例
  • 维护成本:目标网站 UI 变更时,需重新执行「探索→修复」循环
  • 无 headless 优化:虽然支持 headless 模式,但反检测效果最佳需 headed 运行
  • Node.js 依赖:要求预装 Playwright,且与 OpenClaw 的 Python 生态存在异构整合成本

适合人群

  • 需要高频、低成本执行浏览器自动化的开发者与运营团队
  • 面对具有严格反爬机制(如小红书、Instagram、LinkedIn)的自动化场景
  • 已将 OpenClaw browser 工具用于探索,希望规模化降本的进阶用户
  • 具备基础 JavaScript/Node.js 能力,能理解异步流程与选择器调试的技术人员

常规风险

风险类型 说明与缓解措施
账号封禁 即使有人机模拟,高频操作仍可能触发平台风控;建议添加 jitterWait() 随机延时,控制执行频率
会话失效 Cookies 过期后脚本会失败,需定期用 browser 工具重新登录;脚本应优雅处理登录态检查
CDP 锁死 异常退出可能导致 /tmp/openclaw-browser.lock 残留,使用 status/release 命令管理
选择器漂移 前端框架动态生成 class 名,优先使用 data-testid、ARIA 属性或文本内容等稳定选择器
浏览器崩溃 page.close() 正确释放资源,严禁 browser.close() 以免杀死共享 Chrome 进程
敏感信息泄露 脚本中可能硬编码凭证,建议使用环境变量或外部密钥管理服务

技能正文


name: browser-automation-ultra description: "Zero-token browser automation via Playwright scripts with CDP lock management and human-like interaction. Use when: (1) automating any browser-based workflow (publish, login, scrape, fill forms), (2) reducing token cost by converting browser-tool explorations into replayable scripts, (3) avoiding CDP port conflicts between OpenClaw browser and Playwright, (4) needing anti-detection/human-like mouse/keyboard behavior for platforms with bot detection. NOT for: simple URL fetches (use web_fetch instead), tasks that don't need a real browser session."

Browser Automation Ultra

Explore → Record → Replay → Fix. Convert expensive browser-tool interactions into zero-token Playwright scripts that reuse OpenClaw's Chrome session (cookies/login intact).

Prerequisites

Install Playwright (once per machine):

npm install -g playwright
# or in workspace: npm init -y && npm install playwright

No browser download needed — scripts connect to OpenClaw's existing Chrome via CDP.

Architecture

Chrome user-data: ~/.openclaw/browser/openclaw/user-data
       ↕ shared cookies/login (mutually exclusive CDP)
┌──────────────┐    ┌──────────────────┐
│ browser tool │ OR │ Playwright script │
│ (explore)    │    │ (zero token)      │
└──────────────┘    └──────────────────┘
       ↕ managed by browser-lock.sh

Only one CDP client can connect at a time. browser-lock.sh handles the mutex.

Setup

  1. Copy scripts/browser-lock.sh to your workspace scripts/ directory
  2. Copy scripts/utils/human-like.js to your workspace scripts/browser/utils/
  3. chmod +x scripts/browser-lock.sh
  4. Create scripts/browser/ for your automation scripts

Core Workflow

1. Explore (browser tool, costs tokens)

Use the OpenClaw browser tool (snapshot/act) to figure out a workflow. Note selectors, page flow, key waits.

2. Record (write a Playwright script)

Convert steps into a script. Save to scripts/browser/<verb>-<target>.js. Use the template pattern:

const { chromium } = require('playwright');
const { humanDelay, humanClick, humanType, humanThink, humanBrowse } = require('./utils/human-like');

function discoverCdpUrl() {
  try {
    const { execSync } = require('child_process');
    const ps = execSync("ps aux | grep 'remote-debugging-port' | grep -v grep", { encoding: 'utf8' });
    const match = ps.match(/remote-debugging-port=(\d+)/);
    return `http://127.0.0.1:${match ? match[1] : '18800'}`;
  } catch { return 'http://127.0.0.1:18800'; }
}

async function main() {
  const browser = await chromium.connectOverCDP(discoverCdpUrl());
  const context = browser.contexts()[0]; // reuse existing context (cookies/login)
  const page = await context.newPage();
  try {
    // automation here — use human-like functions
    await page.goto('https://example.com', { waitUntil: 'networkidle', timeout: 30000 });
    await humanBrowse(page); // simulate looking at the page
    await humanClick(page, 'button.submit');
    await humanType(page, 'input[name="title"]', 'Hello World');
  } finally {
    await page.close(); // NEVER browser.close() — kills entire Chrome
  }
}
main().then(() => process.exit(0)).catch(e => { console.error('❌', e.message); process.exit(1); });

3. Replay (zero tokens)

./scripts/browser-lock.sh run scripts/browser/my-task.js [args]
./scripts/browser-lock.sh run --timeout 120 scripts/browser/my-task.js

4. Fix (on error)

  1. Read script error output
  2. Re-explore the failing step with browser tool (snapshot) to check current UI
  3. Update script with corrected selectors/logic
  4. Retry

Never guess fixes blindly. Always re-explore the actual page state.

browser-lock.sh

Manages CDP mutex between OpenClaw browser and Playwright scripts.

./scripts/browser-lock.sh run <script.js> [args]    # acquire → run → release (300s default)
./scripts/browser-lock.sh run --timeout 120 <script> # custom timeout
./scripts/browser-lock.sh acquire                    # manual: stop OpenClaw browser, start Chrome
./scripts/browser-lock.sh release                    # manual: kill Chrome, release lock
./scripts/browser-lock.sh status                     # show state

Lock file: /tmp/openclaw-browser.lock. Stale locks auto-recover.

Anti-Detection Rules (MANDATORY)

All scripts must use human-like.js. See references/anti-detection.md for the full rule set.

Summary of critical rules:

❌ Banned ✅ Required
waitForTimeout(3000) fixed delays humanDelay(2000, 4000) random range
input.fill(text) instant fill humanType(page, sel, text) char-by-char with typos
element.click() teleport click humanClick(page, sel) bezier mouse path + hover
Direct page operation after load humanBrowse(page) simulate reading first
nativeSetter.call() DOM injection humanType() or humanFillContentEditable()
Fixed cron schedule jitterWait(1, 10) random offset

Exception: setInputFiles() for file uploads is allowed (no human simulation possible), but add random delays before/after.

human-like.js API

Function Purpose
humanDelay(min, max) Random wait (ms)
humanThink(min, max) Longer pause before form fills
humanClick(page, sel) Bezier mouse move → hover → click with press/release jitter
humanType(page, sel, text, opts) Char-by-char typing, normal distribution speed, 3% typo rate
humanFillContentEditable(page, sel, text) For contenteditable divs (line-by-line Enter + humanType)
humanBrowse(page, opts) Simulate page reading (scroll + mouse wander, 2-5s)
humanScroll(page, opts) Random scroll with occasional reverse
jitterWait(minMin, maxMin) Random delay in minutes for cron tasks

Script Naming Convention

<verb>-<target>.js — e.g. publish-deviantart.js, read-inbox.js, reply-comment.js

Example Scripts

Production-tested scripts in scripts/examples/. Copy to your workspace scripts/browser/ and adapt.

Script Platform Function
publish-deviantart.js DeviantArt Upload image, fill title/desc/tags, submit
publish-xiaohongshu.js 小红书 Publish image note with topic tag association via recommend list
publish-pinterest.js Pinterest Create pin with title/desc, select board
publish-behance.js Behance Upload project with title/desc/tags/categories
read-proton-latest.js Proton Mail Read inbox, output JSON list of emails
read-xhs-comments.js 小红书 Read notification comments, output JSON with reply button index
reply-xhs-comment.js 小红书 Reply to a specific comment by index

Usage pattern:

# Copy examples to workspace
cp scripts/examples/*.js scripts/browser/
cp scripts/utils/human-like.js scripts/browser/utils/

# Run
./scripts/browser-lock.sh run scripts/browser/publish-deviantart.js image.png "Title" "Description" "tag1,tag2"
./scripts/browser-lock.sh run scripts/browser/read-xhs-comments.js --limit 10
./scripts/browser-lock.sh run scripts/browser/reply-xhs-comment.js 0 "回复文字"

All example scripts already use human-like.js for anti-detection.

Cron Integration

cd /path/to/workspace && ./scripts/browser-lock.sh run scripts/browser/task.js

Add jitterWait() at script start to randomize execution time.

Troubleshooting

Problem Fix
Lock held by PID xxx ./scripts/browser-lock.sh release
CDP connection timeout Ensure acquire was called / Chrome is running
Login expired Use browser tool to re-login, then run script
Selector not found Re-explore with browser tool, update script
Script timeout Increase with --timeout flag

Environment Variables

Var Default Description
CDP_PORT auto-discover Override CDP port
CHROME_BIN auto-detect Chrome binary path
HEADLESS auto true/false to force headless

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

browser-automationplaywrightweb-scrapinganti-detectioncdpcost-optimizationsocial-media-publishingheadless-browserjavascriptworkflow-automation

同类 Skill