x-composer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

X Composer

X Composer

Post to X.com via Chrome DevTools Protocol (CDP). Uses real Chrome to bypass anti-bot detection.
通过Chrome DevTools Protocol(CDP)发布内容到X.com。使用真实Chrome浏览器绕过反机器人检测。

Prerequisites

前置条件

  • Google Chrome installed
  • chrome-remote-interface
    npm package
Install if missing:
bash
npm install -g chrome-remote-interface
  • 已安装Google Chrome
  • 已安装
    chrome-remote-interface
    npm包
若未安装,执行以下命令:
bash
npm install -g chrome-remote-interface

Workflow

工作流程

Posting to X involves these steps:
  1. Launch Chrome with CDP (run
    scripts/cdp-launch.js
    )
  2. Wait for X.com compose page to load (~3s)
  3. Type draft text (run
    scripts/cdp-type.js
    )
  4. User reviews and clicks Post manually
发布内容到X的步骤如下:
  1. 启动开启CDP的Chrome浏览器(运行
    scripts/cdp-launch.js
  2. 等待X.com的撰写页面加载完成(约3秒)
  3. 输入草稿文本(运行
    scripts/cdp-type.js
  4. 用户预览并手动点击「发布」按钮

Step 1: Launch Chrome

步骤1:启动Chrome浏览器

Run
scripts/cdp-launch.js
with optional URL argument:
bash
NODE_PATH=$(npm root -g) node scripts/cdp-launch.js
URLPurpose
(default)
https://x.com/compose/post
https://x.com/home
Open home feed
https://x.com/search?q=QUERY&f=live
Search posts
Reuses existing Chrome CDP instance if running. First run requires manual X.com login — session persists in
~/.chrome-cdp-profile
.
Wait ~3 seconds after launch before typing.
运行
scripts/cdp-launch.js
,可附带可选的URL参数:
bash
NODE_PATH=$(npm root -g) node scripts/cdp-launch.js
URL用途
(默认)
https://x.com/compose/post
https://x.com/home
打开首页信息流
https://x.com/search?q=QUERY&f=live
搜索推文
如果已有Chrome CDP实例在运行,则会复用该实例。首次运行需要手动登录X.com——会话会保存在
~/.chrome-cdp-profile
中。
启动后等待约3秒再进行文本输入。

Step 2: Type Draft

步骤2:输入草稿内容

Pipe JSON segments to
scripts/cdp-type.js
via stdin:
bash
echo '[{"text":"Hello world!"}]' | NODE_PATH=$(npm root -g) node scripts/cdp-type.js
通过标准输入将JSON片段管道传输到
scripts/cdp-type.js
bash
echo '[{"text":"Hello world!"}]' | NODE_PATH=$(npm root -g) node scripts/cdp-type.js

Segment Format

片段格式

SegmentEffect
{"text": "string"}
Insert text (emoji/unicode safe)
{"enter": true}
Single line break
{"enter": 2}
Multiple line breaks
片段效果
{"text": "string"}
插入文本(支持表情符号/Unicode)
{"enter": true}
插入单个换行符
{"enter": 2}
插入多个换行符

Example: Multi-paragraph post

示例:多段落内容发布

bash
cat << 'EOF' | NODE_PATH=$(npm root -g) node scripts/cdp-type.js
[
  {"text": "Hook line with emoji"},
  {"enter": 2},
  {"text": "Main content paragraph."},
  {"enter": 2},
  {"text": "- Point one"},
  {"enter": true},
  {"text": "- Point two"},
  {"enter": 2},
  {"text": "https://example.com"},
  {"enter": true},
  {"text": "#hashtag #tags"}
]
EOF
bash
cat << 'EOF' | NODE_PATH=$(npm root -g) node scripts/cdp-type.js
[
  {"text": "Hook line with emoji"},
  {"enter": 2},
  {"text": "Main content paragraph."},
  {"enter": 2},
  {"text": "- Point one"},
  {"enter": true},
  {"text": "- Point two"},
  {"enter": 2},
  {"text": "https://example.com"},
  {"enter": true},
  {"text": "#hashtag #tags"}
]
EOF

Step 3: User Posts

步骤3:用户发布内容

Draft is entered in browser. User reviews and clicks "Post" manually. Never auto-post.
草稿内容已输入到浏览器中。用户预览后手动点击「发布」按钮。绝不会自动发布。

Troubleshooting

故障排除

IssueFix
Chrome not connecting
pkill -f "Chrome.*remote-debugging"
then relaunch
No X.com tab foundLaunch Chrome first, wait 3s
Text not typingClick compose box in browser first
Module not found
npm install -g chrome-remote-interface
Login requiredUse default profile path (
~/.chrome-cdp-profile
), login once
问题解决方法
Chrome无法连接执行
pkill -f "Chrome.*remote-debugging"
后重新启动
未找到X.com标签页先启动Chrome浏览器,等待3秒
文本无法输入先点击浏览器中的撰写框
模块未找到执行
npm install -g chrome-remote-interface
需要登录使用默认配置文件路径(
~/.chrome-cdp-profile
),只需登录一次

Notes

注意事项

  • NODE_PATH=$(npm root -g)
    resolves globally installed
    chrome-remote-interface
  • Input.insertText()
    handles emoji/unicode reliably (not character-by-character)
  • Fixed
    --user-data-dir
    preserves login across Chrome restarts
  • If text appears scrambled, restart Chrome and retry
  • NODE_PATH=$(npm root -g)
    用于解析全局安装的
    chrome-remote-interface
    模块
  • Input.insertText()
    可可靠处理表情符号/Unicode(无需逐个字符输入)
  • 固定的
    --user-data-dir
    可在Chrome重启后保留登录状态
  • 如果文本显示乱码,请重启Chrome后重试