canghe-post-to-x
Posts content and articles to X (Twitter). Supports regular posts with images/videos and X Articles (long-form Markdown). Uses real Chrome with CDP to bypass anti-automation. Use when user asks to "post to X", "tweet", "publish to Twitter", or "share on X".
1How It Works & Mechanism
Instead of Playwright/Puppeteer, it drives a real Chrome instance via CDP to populate content into the actual X UI, with the official description explicitly stating the goal is to bypass anti-automation detection.
Posts text, images, videos, and long-form articles to X via real Chrome browser (bypasses anti-bot detection).
Four content types (regular posts/video posts/quotes/articles) share the same Chrome/CDP infrastructure and clipboard subsystem.
| `scripts/x-video.ts` | Video posts (text + video) |
Key bypass technique: Instead of CDP synthetic key events, it uses osascript to emit real Cmd+V keystrokes because X detects and ignores synthetic events.
Sends real Cmd+V keystroke to Chrome, bypassing CDP's synthetic events that X can detect
Startup flags proactively disable automation feature indicators.
'--disable-blink-features=AutomationControlled',
Articles workflow: md-to-html.ts parses frontmatter/cover image and replaces body images with XIMGPH_n placeholders, while x-article.ts populates the editor via CDP and then reverses placeholders to insert images.
"placeholder": "XIMGPH_1",
Cross-platform clipboard/keystroke subsystem: uses xdotool/ydotool on Linux, osascript on macOS, and PowerShell SendKeys on Windows.
{ cmd: 'xdotool', args: ['key', 'ctrl+v'] },
Defaults to populating without publishing: the script stops after filling in content to wait for manual review; articles only actually publish when --submit is specified.
10. **Publish**: Only with `--submit` flag
Precheck script verifies Chrome, profile isolation, Bun, accessibility permissions, clipboard, paste keys, and conflicts with Chrome.
Checks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, Chrome conflicts.
First-time run requires manual login, with session persisted to the profile.
- First run: log in to X manually (session saved)
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| network | X 编辑器页面(浏览器端访问) |
| cli | bun(经 npx -y 即时拉取) |
| cli | Google Chrome / Chromium(CDP) |
| cli | 真实键击工具:osascript / xdotool / ydotool / powershell.exe |
| package | marked / highlight.js / front-matter / remark-*(md 转换) |
| mcp | Playwright MCP(可选的手工工作流示例调用) |
4Recommended Governance & Evidence
- SKILL.md / 脚本参数: Includes bypassing automation detection, disabling host sandbox, or skipping SSL certificate verification
- SKILL.md / 会话存储: Reads or reuses browser user login state and session cookies
- scripts/: Executes local scripts or commands: npx -y bun ${SKILL_DIR}/scripts/x-browser.ts / x-video.ts / x-quote.ts / x-
- 网络端点: Declares external network access: CDP port discovery http://127.0.0.1:<port>/json/version and WebSocket connection to CDP (x-utils.ts
- 本地工作目录: File read/write and artifact output: Chrome profile directory (configurable via X_BROWSER_CHROME_PATH / profile arguments)
5Second-Pass Verification
- [ok] 反自动化绕过动机 — SKILL.md 描述、regular-posts.md 的 How It Works 与 paste-from-clipboard.ts 顶部注释三处一致声明绕过检测。
- [ok] AutomationControlled 标志 — 风险扫描在 x-article.ts:117 / x-browser.ts:44 / x-quote.ts:48 / x-video.ts:48 四处定位同一参数,判红据成立。
- [ok] 四条内容路径 — SKILL.md Script Reference 与各命令行示例互证 x-browser/x-video/x-quote/x-article 四个入口。
- [ok] 剪贴板/键击跨平台适配 — paste-from-clipboard.ts 正文完整展开,pasteMac/pasteLinux/pasteWindows 分派逐字可核。
- [ok] 长文占位符机制 — articles.md 的 images XIMGPH_n 与 Workflow 第 8 步『反向替换』描述自洽。
- [ok] 凭证读取 — 「凭证/环境变量」39 条命中均为 ${SKILL_DIR}/$HOME/profile 参数与示例,未见密钥/cookie 文件读取;凭据即 profile 登录态,与结论一致。
- [unlocatable] 主脚本的 CDP DOM 细节 — x-browser/x-video/x-quote/x-article.ts 全文未在 bundle 展开,文本注入与 DOM 操作细节以 SKILL.md/references 描述与扫描行为据,未代码级复核。
- [ok] Playwright MCP 引用 — 仅出现在 regular-posts.md 的可选手工工作流示例,非脚本内置依赖,不改变档位。
6Verdict & Scenarios
aa885729a2c33e40…