Use OpenClaw to Tweet from VPS Without Getting Banned: Headed Browser + Xvfb Solution
I. Introduction
Problem Background
You have a VPS (Virtual Private Server) and want to automate Twitter posting.
But here's the problem:
- ❌ Twitter API requires approval and has many restrictions
- ❌ Selenium is easily detected
- ❌ Puppeteer headless mode is blocked by Twitter's anti-scraping measures
- ❌ VPS has no desktop environment, browser cannot start
The Core Contradiction: Twitter requires a headed browser (with GUI), but VPS has no monitor.
Goal of This Article
Through the Xvfb + Chromium + VNC + CDP solution, achieve on VPS:
✅ Headed browser execution (bypass anti-scraping detection)
✅ Remote visual debugging (view browser via VNC)
✅ Automation control (CDP protocol)
✅ Login state persistence (no need to re-login)
✅ One-click setup (via OpenClaw)
Applicable Scenarios
This solution is not limited to Twitter; it can be extended to:
- Xiaohongshu (strict anti-scraping)
- WeChat Official Account (requires QR code login)
- Instagram (detects headless mode)
- LinkedIn (complex interactions)
- Taobao/JD (risk control systems)
Any scenario requiring a headed browser on VPS can use this architecture.
II. Core Concepts
Before starting configuration, we need to understand 4 core concepts.
2.1 Headed Mode vs Headless Mode
What is Headed Mode?
Definition: The browser has a complete graphical interface, just like opening Chrome on your computer.
Advantages:
- ✅ Visual debugging: See exactly what's happening in the browser
- ✅ Good compatibility: Fully renders pages, supports all web features
- ✅ Hard to detect: Behavior matches real users, difficult for anti-scraping systems to identify
- ✅ Supports complex interactions: Drag-and-drop, right-click menus, popups, etc.
Disadvantages:
- ❌ Requires display environment: Must have a physical or virtual monitor
- ❌ High resource consumption: Needs to render GUI, consumes GPU memory and CPU
- ❌ Not suitable for large-scale concurrency: Each browser instance consumes significant resources
What is Headless Mode?
Definition: Browser runs without a graphical interface, pure background operation, no visible window rendering.
Advantages:
- ✅ Low resource consumption: No GUI rendering, saves memory and CPU
- ✅ Fast startup: Skips graphics initialization, starts in 1-2 seconds
- ✅ Suitable for batch tasks: Can run multiple instances simultaneously
Disadvantages:
- ❌ Easily detected: Missing WebGL, Canvas fingerprints, easily identified
- ❌ Difficult debugging: Cannot see the interface, must troubleshoot through logs
- ❌ Not supported by some websites: Twitter, Xiaohongshu, etc. detect and block access
Comparison Table
| Metric | Headed Mode | Headless Mode |
|---|---|---|
| GUI | ✅ Yes | ❌ No |
| Memory Usage | ~500MB | ~200MB |
| CPU Usage | Medium | Low |
| Startup Speed | 3-5 seconds | 1-2 seconds |
| Anti-Scraping Capability | Strong (hard to detect) | Weak (easy to detect) |
| Debugging Difficulty | Low (visual) | High (blind operation) |
| Applicable Scenarios | Complex sites, anti-scraping sites | Simple crawlers, batch tasks |
Conclusion: For websites with anti-scraping mechanisms like Twitter and Xiaohongshu, headed mode is mandatory.
2.2 Xvfb - Virtual Display Server
What Is It?
Xvfb = X Virtual Framebuffer
It's a tool that simulates a display environment on servers without physical monitors.
Why Is It Needed?
VPS servers typically lack physical monitors, but headed browsers require a display environment to start.
The Contradiction:
- Browser: I need a monitor to run
- VPS: I don't have a monitor
The Solution:
- Xvfb: I create a "virtual monitor" that the browser thinks exists, but actually doesn't
Analogy
- Physical Monitor = Real television
- Xvfb = Virtual television (the browser thinks it exists, but it doesn't)
The browser connects to Xvfb, renders pages normally, but the output never appears on any physical screen.
Working Principle
┌─────────────────────────────────┐
│ VPS Server (No Physical Monitor)│
├─────────────────────────────────┤
│ Xvfb Creates Virtual Display :99 │
│ (Resolution 1920x1080, 24-bit) │
│ ↓ │
│ Chromium Connects to :99 │
│ (Thinks monitor exists, renders) │
│ ↓ │
│ Pages Load, JavaScript Executes │
└─────────────────────────────────┘
Key Parameters:
-
:99- Display number (can be :0, :1, :99, etc.) -
1920x1080x24- Resolution and color depth
2.3 VNC - Remote Desktop
What Is It?
VNC = Virtual Network Computing
It's a protocol for remotely viewing and controlling server desktops.
Why Is It Needed?
Although Xvfb creates a virtual display, we cannot see what the browser is doing.
VNC's Role:
- ✅ Debugging: See actual browser operation
- ✅ Manual operations: First-time login, captcha handling
- ✅ Verification: Confirm automation scripts work correctly
Port Mapping
Xvfb display numbers correspond to VNC ports:
| Xvfb Display | VNC Port |
|---|---|
| :0 | 5900 |
| :1 | 5901 |
| :99 | 5999 |
Formula: VNC Port = 5900 + Display Number
Connection Flow
┌──────────┐ ┌─────────────┐ ┌──────────┐
│ Local PC │ → │ VNC Viewer │ → │ VPS :5999│
│ (You) │ │(Remote Desk)│ │ (Server) │
└──────────┘ └─────────────┘ └──────────┘
↓
┌──────────┐
│ Xvfb :99 │
│(Virtual) │
└──────────┘
↓
┌──────────┐
│Chromium │
│(Browser) │
└──────────┘
You connect to VPS via VNC Viewer from your local PC and can see the Chromium browser interface.
2.4 CDP - Browser Control Protocol
What Is It?
CDP = Chrome DevTools Protocol
It's the official standard protocol provided by Chrome/Chromium for remotely controlling browsers.
Why Is It Needed?
VNC only lets us "see" the browser; automation requires "controlling" it.
CDP's Role:
- ✅ Automation control: Control browser via code (click, input, screenshots, etc.)
- ✅ No Selenium required: Use native protocol directly, more stable
- ✅ Official support: Maintained by Chrome/Chromium, excellent compatibility
Port
CDP default port is 9222 (customizable).
When starting Chromium, add the parameter:
--remote-debugging-port=9222
Communication Flow
┌──────────────────┐ ┌─────────────┐ ┌──────────┐
│ Playwright Script│ ←───→ │ CDP :9222 │ ←───→ │Chromium │
│ (Automation) │ │(Control Prot)│ │(Browser) │
└──────────────────┘ └─────────────┘ └──────────┘
↓ ↓ ↓
Send Commands Protocol Conversion Execute Actions
(Click Button) (JSON-RPC) (Simulate Click)
III. Overall Architecture
Now let's combine the 4 concepts and see the complete architecture.
Architecture Diagram
┌─────────────────────────────────────────────────────────┐
│ VPS Server (No Physical Monitor) │
├─────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────────────────────────────────┐ │
│ │ Xvfb :99 (Virtual Display 1920x1080x24) │ │
│ └────────────────────────────────────────────┘ │
│ ↓ │
│ ┌────────────────────────────────────────────┐ │
│ │ Chromium (Headed Mode) │ │
│ │ ├─ CDP :9222 (Automation Control API) │ │
│ │ └─ User Data Dir (Save Login State) │ │
│ │ /root/.local/share/chromium-profile │ │
│ └────────────────────────────────────────────┘ │
│ ↑ │
│ ┌────────────────────────────────────────────┐ │
│ │ VNC Server :5999 (Remote View API) │ │
│ └────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────┘
↑ ↑
│ │
┌──────────────┐ ┌─────────────────┐
│ VNC Viewer │ │ Playwright │
│ (Debug) │ │ (Automation) │
└──────────────┘ └─────────────────┘
Data Flow Explanation
1. Xvfb Provides Virtual Display Environment
- Creates virtual display
:99 - Resolution 1920x1080, 24-bit color depth
- Runs in background, doesn't占用 physical monitor
2. Chromium Connects to Virtual Display
- Starts in headed mode
- Connects to Xvfb
:99 - Renders pages normally, executes JavaScript
3. User Data Dir Saves Login State
- Specifies data directory:
/root/.local/share/chromium-profile - Automatically saves cookies, cache, browsing history
- Login state restores automatically after restart
- No need to manually export/import cookies
4. VNC Connects to Virtual Display
- VNC Server listens on port 5999
- Connects to Xvfb
:99 - User views browser remotely via VNC Viewer
5. CDP Connects to Chromium
- Chromium enables CDP port 9222
- Playwright sends control commands via CDP
- Achieves automation (filling, clicking, screenshots, etc.)
Key Features
✅ Headed Mode: Bypass Twitter anti-scraping detection
✅ Virtual Display: No physical monitor required
✅ Remote Visibility: View browser via VNC
✅ Automation Control: CDP protocol
✅ Login Persistence: User Data Dir auto-saves
✅ Stable & Reliable: Chromium more stable than Chrome
IV. One-Click Configuration
After understanding the architecture, let's configure the environment.
Complete Prompt for OpenClaw
Copy the following prompt and send it to OpenClaw:
I need to configure Twitter auto-posting environment on VPS.
Please help me complete the following configuration:
1. Install Dependencies
- Xvfb (Virtual Display)
- x11vnc (VNC Server)
- Chromium Browser
- Node.js 22+
- Playwright
2. Start Services
- Xvfb :99 (Resolution 1920x1080x24)
- x11vnc :5999 (Connect to :99 display)
- Chromium (CDP Port 9222, Headed Mode)
* Data Directory: /root/.local/share/chromium-shared-profile
* Parameters: --no-sandbox --disable-dev-shm-usage
3. Create Auto-Posting Script
- Connect to CDP :9222
- Open Twitter compose page
- Fill content and publish
4. Environment Variables
- DISPLAY=:99
- XAUTHORITY=/root/.Xauthority
After completion, tell me:
- VNC connection address
- How to test auto-posting
OpenClaw will automatically complete all configuration.
Configuration Complete
OpenClaw will return:
✅ Configuration Complete!
VNC Connection Address: Your_VPS_IP:5999
CDP Port: 9222
Next Steps:
1. Use VNC Viewer to connect to VPS
2. Manually log into Twitter in the browser
3. Test auto-posting:
Send me the command: "Help me post a test tweet"
V. Manual Operation Steps
After configuration, 3 manual operations are required.
5.1 Connect VNC
Download VNC Viewer
Download based on your operating system:
- Windows: https://www.realvnc.com/en/connect/download/viewer/windows/
- macOS: https://www.realvnc.com/en/connect/download/viewer/macos/
- Linux:
apt-get install tigervnc-viewer
# or
yum install tigervnc
Connection Steps
- Open VNC Viewer
- Enter address:
Your_VPS_IP:5999- Example:
123.45.67.189:5999
- Example:
- Click "Connect"
First Connection
- May see black screen (normal behavior)
- Wait 2-3 seconds, Chromium window will appear
- If screen stays black, check if Chromium started:
ps aux | grep chromium
5.2 First-Time Twitter Login
Operate in VNC
After successful connection, you'll see the Chromium browser window.
操作步骤:
Access Twitter
- Enter in address bar:
https://twitter.com - Manually complete login
Important Notes
✅ Only Need to Login Once
- Login state automatically saves to User Data Dir
- Login state automatically restores after server restart
- No need to manually export/import cookies
✅ Login State Persistence Mechanism
- Chromium uses
--user-data-dirparameter - All data saved to:
/root/.local/share/chromium-shared-profile - Includes: Cookies, cache, history, extensions, etc.
⚠️ Precautions
- Do not delete User Data Dir directory
- Do not log into the same account elsewhere (may trigger security verification)
- If login state is lost, simply re-login manually
5.3 Test Auto-Posting
After login is complete, test the automation functionality.
Command for OpenClaw
Help me post a test tweet: "This is a test tweet automatically published via VPS 🚀"
What OpenClaw Will Do
- Call Auto-Posting Script
node /root/post-tweet.js "This is a test tweet automatically published via VPS 🚀"
-
Connect to CDP
- Connect to
http://localhost:9222 - Get existing browser context
- Connect to
-
Automation Operations
- Open Twitter compose page
- Fill tweet content
- Click "Post" button
Return Result
✅ Tweet Published
View in VNC
If you keep VNC connected, you can see in real-time:
- Browser automatically opens new tab
- Navigate to Twitter compose page
- Text box automatically fills with content
- "Post" button automatically clicked
- Tweet published successfully
This is the power of automation: You just send the command, the rest is fully automatic.
Verify Tweet
- Refresh Twitter webpage to see if tweet was published
- Or view Twitter homepage in VNC
VI. Extension to Other Websites
This architecture is not limited to Twitter; it can be extended to any website requiring a headed browser.
6.1 Applicable Scenarios
Websites Also Requiring Headed Mode:
| Website | Reason | Challenges |
|---|---|---|
| Xiaohongshu | Strict anti-scraping, detects headless mode | Need to simulate real user behavior |
| WeChat Official Account | Requires QR code login | Need manual QR scan |
| Detects WebGL, Canvas fingerprints | Headless mode blocked | |
| Complex interactions, risk control | Needs full rendering | |
| Taobao/JD | Slider captcha, risk control | Needs real browser environment |
| Douyin/Kuaishou | Video upload, complex editor | Needs complete DOM manipulation |
Core Characteristics:
- ✅ Has anti-scraping detection
- ✅ Requires login
- ✅ Has complex interactions
- ✅ Detects browser fingerprints
6.2 Universal Architecture
Core Remains Unchanged:
- Xvfb virtual display
- VNC remote viewing
- CDP automation control
- User Data Dir saves login state
Needs Adjustment:
- Page URLs
- Page selectors (button, input field locators)
- Operation flow (click sequence, wait times)
VII. Summary
Technology is not isolated; architectures are reusable; thinking can be transferred.
When you understand the logic behind this architecture, what you possess is not just an auto-tweeting tool, but a key to unlock the automation gateway.
Copy the prompt to OpenClaw, one-click configuration, one-click launch, let machines work for you, let time create value for you.
This is the power of automation. 🚀
Top comments (0)