jackwener/OpenCLI · error · CommandExecutionError
Browser session required for twitter follow
Error message
Browser session required for twitter follow
What it means
The single `twitter follow` command navigates a live Page to x.com/<username> and evaluates in-page scripts, so it throws CommandExecutionError if no browser Page session was supplied (page is falsy). Nothing can be attempted without an attached browser.
Source
Thrown at clis/twitter/follow.js:17
import { CommandExecutionError, TimeoutError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
cli({
site: 'twitter',
name: 'follow',
access: 'write',
description: 'Follow a Twitter user',
domain: 'x.com',
strategy: Strategy.UI,
browser: true,
args: [
{ name: 'username', type: 'string', positional: true, required: true, help: 'Twitter screen name (without @)' },
],
columns: ['status', 'message'],
func: async (page, kwargs) => {
if (!page)
throw new CommandExecutionError('Browser session required for twitter follow');
const username = kwargs.username.replace(/^@/, '');
await page.goto(`https://x.com/${username}`);
await page.wait({ selector: '[data-testid="primaryColumn"]' });
const result = await page.evaluate(`(async () => {
let writeStarted = false;
try {
let attempts = 0;
let followBtn = null;
let unfollowTestId = null;
while (attempts < 20) {
// Check if already following (button shows screen_name-unfollow)
unfollowTestId = document.querySelector('[data-testid$="-unfollow"]');
if (unfollowTestId) {
return { ok: true, message: 'Already following @${username}.' };
}
// Look for the Follow buttonView on GitHub (pinned to 49907e53dc)
Solutions
- Establish the browser session (start the daemon / connect Chrome) before running `twitter follow`.
- Add an existence check on the page in wrapper scripts before invoking the command.
- If sessions drop between commands, reconnect and batch follow operations within one session.
Example fix
// before opencli twitter follow alice # browser not started // after opencli connect # start/connect the managed browser first opencli twitter follow alice
Defensive patterns
Strategy: try-catch
Validate before calling
// Verify a usable page exists before calling single follow
function requirePageForFollow(page) {
if (!page || typeof page.goto !== 'function' || typeof page.evaluate !== 'function') {
throw new Error('Browser session required for twitter follow: connect the browser first');
}
} Type guard
function isUsablePage(p) {
return p !== null && p !== undefined && typeof p.goto === 'function' && typeof p.wait === 'function' && typeof p.evaluate === 'function';
} Try / catch
try {
await follow(username);
} catch (e) {
if (e.code === 'COMMAND_EXEC' && e.message.includes('Browser session required')) {
await connectBrowser();
return retry(follow, username);
}
throw e;
} Prevention
- Establish the browser session before the first browser-backed command in a script.
- Health-check the daemon/extension connection after long idle periods.
- Batch follow operations into one session to reduce reconnect windows.
- Wrap session acquisition and command execution in the same setup/teardown flow.
When it happens
Trigger: Running `opencli twitter follow <username>` with no browser daemon/extension connected; calling the command's func directly with page = null/undefined; the browser connection was lost before func executed.
Common situations: Scripting against the module API without establishing a session first; running before starting the managed Chrome instance; the daemon crashed between commands leaving no active session.
Related errors
- Browser session required for twitter follow-batch
- 12306 whoami failed: ${probe.detail}
- Browser session required for bilibili comments
- Browser session required for instagram note
- Browser session required for linkedin salesnav-search
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9b431bf0994b909e.
Report an issue: GitHub.