x-twitter-browser
Execute browser actions on X using a saved login session, without the official X API.
Users log in once via a visible browser window. The session is saved and reused for all subsequent headless operations.
After installing into OpenClaw, the skill lives at:
CODEBLOCK0
Commands below assume you run from the skill root directory:
CODEBLOCK1
Use cases
- - You want to automate X actions without the official API
- Running headless on a VM or Linux server
- Building a long-term extensible browser skill for X automation
Architecture
This skill has two layers:
1. Session layer
Manages login and cookie persistence (stored in the centralised OpenClaw auth directory):
- -
scripts/setup_session.py — log in via visible browser, save cookies - INLINECODE1 — Playwright storage state
2. Action layer
Performs actions using the saved session:
- - Post tweet: INLINECODE2
- Reply to tweet: INLINECODE3
- Repost (retweet) / Quote tweet: INLINECODE4
- Like / Unlike tweet: INLINECODE5
- Bookmark / Remove bookmark: INLINECODE6
Dependencies
First-time setup (installs Playwright + Chromium):
CODEBLOCK2
Note: Chromium download is ~150MB and may take several minutes on first run.
OpenClaw: When running setup.sh via OpenClaw, it executes in the background and the user cannot see the echo output. Forward each progress message to the user so they know the setup is progressing.
Session management
Session cookies are stored in ~/.openclaw/auth/x-twitter/cookies.json (centralised auth directory shared by all OpenClaw skills, survives skill updates). Do not commit or share this file.
Log in (first time or when session expires)
This is a two-phase process. You (the agent) drive both phases — the user does not need to touch the terminal.
Phase 1 — Launch the login browser:
CODEBLOCK3
This opens a visible browser window at the X login page. The script prints a banner and waits for Enter on stdin before saving cookies. Once the browser is open, tell the user:
A browser window has opened with the X login page. Please log in with your account (username, password, 2FA if prompted). Once you see the home timeline, let me know.
Then wait for the user to confirm they have logged in. Do NOT send Enter yet.
Phase 2 — After the user confirms they are logged in:
Send Enter (newline) to the waiting script's stdin to trigger cookie saving. Check the output for Session saved to confirm success.
If the output shows a WARNING ("The page still looks like a login page"), ask the user to double-check they are actually logged in and can see the home timeline. Once confirmed, send Enter again to save anyway.
Verify session
CODEBLOCK4
Success looks like:
CODEBLOCK5
If verification fails, re-run the two-phase login flow above.
OpenClaw / headless-only environments
If running on a headless VM, set up the session on a local machine first, then copy:
CODEBLOCK6
Workflow
1. Set up session (once)
Follow the two-phase login flow in the "Session management" section above. Do not simply run setup_session.py and tell the user to press Enter — you must run it, wait for the user to confirm login, then send Enter yourself.
2. Post a tweet
CODEBLOCK7
3. Reply to a tweet
CODEBLOCK8
4. Repost (retweet) a tweet
Plain repost (no comment):
CODEBLOCK9
Quote tweet (repost with your comment):
CODEBLOCK10
For both reply and repost, --tweet accepts a full URL or just the tweet ID.
5. Like a tweet
CODEBLOCK11
Unlike (remove like):
CODEBLOCK12
6. Bookmark a tweet
CODEBLOCK13
Remove bookmark:
CODEBLOCK14
For like and bookmark, --tweet accepts a full URL or just the tweet ID.
Rules
- -
--verify-only success means the session is likely usable - If the page behaves oddly, buttons are disabled, or extra dialogs appear, re-run INLINECODE15
- If Chromium fails to start, run
./scripts/setup.sh to install browser deps
Operational requirements
- - Before the first action, check if session exists; if not, run the two-phase login flow (see "Session management" above)
- Run
--verify-only before any write operation - Confirm the action and content before executing
- Do not commit cookies to the repo (
~/.openclaw/auth/) - Call
scripts/*.py directly
Troubleshooting
No saved session. Run setup_session.py first to log in to X.
No cookies found at ~/.openclaw/auth/x-twitter/cookies.json. Run the two-phase login flow (see "Session management" above).
Session is not authenticated
- - Session cookies expired (typically lasts days to weeks)
- Account triggered extra verification
Re-run the two-phase login flow to log in again.
x-twitter-browser
使用已保存的登录会话在X上执行浏览器操作,无需官方X API。
用户通过可见的浏览器窗口登录一次。会话会被保存并用于所有后续的无头操作。
安装到OpenClaw后,该技能位于:
bash
~/.openclaw/workspace/skills/x-twitter-browser/
以下命令假设你从技能根目录运行:
bash
cd ~/.openclaw/workspace/skills/x-twitter-browser
使用场景
- - 你想要自动化X操作但不想使用官方API
- 在虚拟机或Linux服务器上无头运行
- 为X自动化构建长期可扩展的浏览器技能
架构
该技能包含两层:
1. 会话层
管理登录和Cookie持久化(存储在集中的OpenClaw认证目录中):
- - scripts/setup_session.py — 通过可见浏览器登录,保存Cookie
- ~/.openclaw/auth/x-twitter/cookies.json — Playwright存储状态
2. 操作层
使用已保存的会话执行操作:
- - 发布推文:scripts/posttweet.py
- 回复推文:scripts/replypost.py
- 转发(转推)/引用推文:scripts/repostpost.py
- 点赞/取消点赞:scripts/likepost.py
- 书签/移除书签:scripts/bookmark_post.py
依赖
首次设置(安装Playwright + Chromium):
bash
./scripts/setup.sh
注意: Chromium下载约150MB,首次运行可能需要几分钟。
OpenClaw: 通过OpenClaw运行setup.sh时,它在后台执行,用户看不到echo输出。请将每条进度消息转发给用户,让他们知道设置正在进行中。
会话管理
会话Cookie存储在~/.openclaw/auth/x-twitter/cookies.json(所有OpenClaw技能共享的集中认证目录,技能更新后仍然保留)。请勿提交或共享此文件。
登录(首次或会话过期时)
这是一个两阶段过程。你(代理)驱动两个阶段——用户无需接触终端。
阶段1 — 启动登录浏览器:
bash
python3 scripts/setup_session.py
这会在X登录页面打开一个可见的浏览器窗口。脚本会打印横幅并等待stdin上的回车键,然后保存Cookie。浏览器打开后,告诉用户:
已打开一个显示X登录页面的浏览器窗口。请使用你的账号登录(用户名、密码,如有提示还需输入双重验证)。当你看到首页时间线后,请告诉我。
然后等待用户确认他们已登录。此时不要发送回车键。
阶段2 — 用户确认登录后:
向等待脚本的stdin发送回车键(换行符)以触发Cookie保存。检查输出中是否有Session saved来确认成功。
如果输出显示警告(页面看起来仍然是登录页面),请用户仔细检查他们是否确实已登录并能看到首页时间线。确认后,再次发送回车键以强制保存。
验证会话
bash
python3 scripts/setup_session.py --verify-only
成功时显示:
text
Session looks valid: https://x.com/home
如果验证失败,重新运行上述两阶段登录流程。
OpenClaw / 仅无头环境
如果在无头虚拟机上运行,先在本地机器上设置会话,然后复制:
bash
scp ~/.openclaw/auth/x-twitter/cookies.json user@server:~/.openclaw/auth/x-twitter/cookies.json
工作流程
1. 设置会话(一次)
按照上述会话管理部分的两阶段登录流程操作。不要简单地运行setup_session.py然后告诉用户按回车键——你必须运行它,等待用户确认登录,然后自己发送回车键。
2. 发布推文
bash
python3 scripts/post_tweet.py \
--text 你好
3. 回复推文
bash
python3 scripts/reply_post.py \
--tweet https://x.com/username/status/123456789 \
--text 我的回复
4. 转发(转推)推文
纯转发(无评论):
bash
python3 scripts/repost_post.py \
--tweet https://x.com/username/status/123456789
引用推文(带评论转发):
bash
python3 scripts/repost_post.py \
--tweet https://x.com/username/status/123456789 \
--text 我的评论
对于回复和转发,--tweet接受完整URL或仅推文ID。
5. 点赞推文
bash
python3 scripts/like_post.py \
--tweet https://x.com/username/status/123456789
取消点赞(移除点赞):
bash
python3 scripts/like_post.py \
--tweet https://x.com/username/status/123456789 \
--undo
6. 书签推文
bash
python3 scripts/bookmark_post.py \
--tweet https://x.com/username/status/123456789
移除书签:
bash
python3 scripts/bookmark_post.py \
--tweet https://x.com/username/status/123456789 \
--undo
对于点赞和书签,--tweet接受完整URL或仅推文ID。
规则
- - --verify-only成功表示会话很可能可用
- 如果页面行为异常、按钮被禁用或出现额外对话框,重新运行setup_session.py
- 如果Chromium启动失败,运行./scripts/setup.sh安装浏览器依赖
操作要求
- - 在首次操作前,检查会话是否存在;如果不存在,运行两阶段登录流程(见上方会话管理)
- 在任何写入操作前运行--verify-only
- 在执行前确认操作和内容
- 不要将Cookie提交到仓库(~/.openclaw/auth/)
- 直接调用scripts/*.py
故障排除
No saved session. Run setup_session.py first to log in to X.
在~/.openclaw/auth/x-twitter/cookies.json未找到Cookie。运行两阶段登录流程(见上方会话管理)。
Session is not authenticated
- - 会话Cookie已过期(通常持续数天到数周)
- 账号触发了额外验证
重新运行两阶段登录流程以重新登录。