baoyu-post-to-weibo
Posts content to Weibo (微博). Supports regular posts with text, images, and videos, and headline articles (头条文章) with Markdown input via Chrome CDP. Use when user asks to "post to Weibo", "发微博", "发布微博", "publish to Weibo", "share on Weibo", "写微博", or "微博头条文章".
1How It Works & Mechanism
The implementation approach drives a real local Chrome instance: locate the Chrome executable → launch an instance with a debugging port enabled (isolated profile) → wait for the debugging port to be ready → connect via CDP WebSocket → attach to the target page.
export async function launchChrome(url: string, profileDir: string, chromePathOverride?: string): Promise<number> {
Bypassing anti-automation detection is an explicit design choice of this skill: the opening paragraph of SKILL.md highlights it as a selling point, and the code disables Chrome's automation feature flags.
extraArgs: ['--disable-blink-features=AutomationControlled', '--start-maximized'],
The primary method for content injection is 'real keystroke pasting' rather than synthetic events, with the rationale explicitly stated in the script's comments: websites can detect and ignore CDP synthetic events.
This bypasses CDP's synthetic events which websites can detect and ignore.
Text input for regular posts uses CDP Input.insertText with a fallback to execCommand upon failure; media uploads pass file paths directly to the page's file input, verified by counting blob:/data: resources.
await cdp.send('Input.insertText', { text }, { sessionId });
Headline articles are handled through ProseMirror editor on card.weibo.com: populate title/summary → paste HTML → replace image placeholders one by one via 'copy image + real paste keystroke' → verify remaining placeholders and image counts.
// Method 1: Copy HTML to system clipboard, then real paste keystroke
Platform character limits are hardcoded and handled automatically: 32 characters for titles, 44 characters for summaries, with overlong text truncated at punctuation boundaries or regenerated from the body.
const TITLE_MAX_LENGTH = 32;
Can take over or reuse an already running debugging Chrome: matches processes in the process list by profile directory + --remote-debugging-port, terminating only instances belonging to its own profile when necessary.
if (!line.includes(profileDir) || !line.includes('--remote-debugging-port=')) continue;
Login state relies on a persistent Chrome profile, requiring a one-time manual login on the first run for long-term reuse; the script only fills content into the page, leaving publication for the user to confirm manually.
All scripts only fill content into the browser, user must review and publish manually
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| network | 浏览器访问 weibo.com 与 card.weibo.com(发帖与头条文章编辑器) |
| network | 头条文章编辑器入口 |
| cli | 本地 Chrome/Chromium(--remote-debugging-port + --user-data-dir,带 AutomationControlled 关闭参数) |
| cli | 粘贴按键注入工具(macOS osascript / Linux xdotool 或 ydotool / Windows powershell.exe) |
| cli | 剪贴板工具(macOS swift 临时脚本 / Linux wl-copy 或 xclip / Windows PowerShell) |
| cli | ps(进程枚举,用于复用/清理调试 Chrome) |
| package | baoyu-chrome-cdp(npm,仓库 packages/ 内共享包:CDP 连接、Chrome 查找与启动、按键/剪贴板基础件) |
| package | baoyu-md(npm,仓库 packages/ 内共享包:Markdown → HTML,供头条文章使用) |
| cli | bun(内部以 npx -y bun 调起同目录辅助脚本) |
4Recommended Governance & Evidence
- SKILL.md / 脚本: Calling undocumented or reverse-engineered private APIs / spoofing client identifiers
- SKILL.md / 脚本参数: Involves bypassing automation detection, disabling host sandbox, or skipping SSL certificate validation
- SKILL.md / 会话存储: Reading or reusing browser user login state and session cookies
- scripts/: Executing local scripts or commands: bun {baseDir}/scripts/weibo-post.ts <text> --image/--video …
- 外部 API: Publishing posts, creating, or modifying resources on external platforms
- 本地工作目录: File read/write and artifact output: Chrome profile directory (default baoyu-skills/chrome-profile hierarchy, persisting login session and browser data)
5Second-Pass Verification
- [ok] 反自动化检测绕过(判红主因) — 三处证据互相印证:SKILL.md 'bypasses anti-bot detection';weibo-utils.ts `extraArgs: ['--disable-blink-features=AutomationControlled', '--start-maximized'],`(launchChrome 传给 launchChromeBase);paste-from-clipboard.ts 'This bypasses CDP's synthetic events which websites can detect and ignore.'
- [ok] 真实按键是第一手段而非兜底 — weibo-article.ts 注释排序为 '// Method 1: Copy HTML to system clipboard, then real paste keystroke',失败后才走 DataTransfer paste 事件;图片替换循环直接 pasteFromClipboard('Google Chrome', 5, 1000)。
- [ok] 凭证面确认(无密钥读取,靠 profile 会话) — 全目录 process.env/API_KEY/TOKEN/SECRET/.env 扫描零命中;SKILL.md 说明登录态由 Chrome profile 持久化(First run: log in to Weibo manually (session saved)),EXTEND.md 仅支持默认 profile 一项。
- [ok] 外部端点仅微博自家域名 — grep https:// 命中 WEIBO_HOME_URL=https://weibo.com/ 与 WEIBO_ARTICLE_URL=https://card.weibo.com/article/v3/editor,另有一处仅作日志措辞的 'src: https://...';无第三方 API/CDN。
- [ok] 平台限制与自检 — MAX_FILES=18、TITLE_MAX_LENGTH=32、SUMMARY_MAX_LENGTH=44 均在源码;SKILL.md 的 Post-Composition Check(剩余 WBIMGPH_ 占位符、预期 vs 实际图片数)与代码校验逻辑一致。
- [ok] 进程清理不会误杀用户浏览器 — killChromeByProfile 只对同时包含 profileDir 与 '--remote-debugging-port=' 的行取 pid 并 SIGTERM;SKILL.md 用 CRITICAL 明确禁止 `pkill -f "Google Chrome"`。
- [ok] 无其他安全降级 — grep no-sandbox / rejectUnauthorized / --insecure / NODE_TLS_REJECT / disable-web-security 零命中;Chrome 参数仅为调试端口、profile、AutomationControlled 与最大化窗口。
- [ok] 元数据(license/stars/commit) — git HEAD=1567581c26ec29f4216c6e6835415bf30343b0e3;仓库根 LICENSE=MIT(Copyright (c) 2026 Jim Liu);GitHub API stars=25926、pushed_at=2026-09-10T15:13:43Z。
6Verdict & Scenarios
5673e558aeace4cc…