jackwener/OpenCLI · error · CommandExecutionError
Browser session required for twitter like
Error message
Browser session required for twitter like
What it means
The twitter like CLI requires an active browser session (a logged-in page handle). When the `page` argument is falsy, the command cannot interact with Twitter, so it immediately throws this CommandExecutionError instead of proceeding to parse the tweet URL. It is a precondition check, thrown before any navigation happens.
Source
Thrown at clis/twitter/like.js:19
import { CommandExecutionError, TimeoutError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { parseTweetUrl, buildTwitterArticleScopeSource } from './shared.js';
cli({
site: 'twitter',
name: 'like',
access: 'write',
description: 'Like a specific tweet',
domain: 'x.com',
strategy: Strategy.UI, // Utilizes internal DOM flows for interaction
browser: true,
args: [
{ name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the tweet to like' },
],
columns: ['status', 'message'],
func: async (page, kwargs) => {
if (!page)
throw new CommandExecutionError('Browser session required for twitter like');
const target = parseTweetUrl(kwargs.url);
await page.goto(target.url);
await page.wait({ selector: '[data-testid="primaryColumn"]' }); // Wait for tweet to load completely
const result = await page.evaluate(`(async () => {
let writeStarted = false;
try {
${buildTwitterArticleScopeSource(target.id)}
// Poll for the tweet to render. We scope state probes to the
// article matching the requested status id — on conversation
// pages multiple articles render and a bare querySelector would
// grab the first one (silent: like the wrong tweet).
let attempts = 0;
let likeBtn = null;
let unlikeBtn = null;
let targetArticle = null;
while (attempts < 20) {
targetArticle = findTargetArticle();View on GitHub (pinned to 49907e53dc)
Solutions
- Open/attach a browser session before running the command (e.g. run the session/auth command first, or pass the browser/session flag)
- If scripting, pass the page handle into the command's func
- Check that the browser did not crash or exit earlier in the pipeline
- Verify the CLI invocation includes the required browser-session options per the library docs
Example fix
// before
await clis.twitter.like.func(null, { url: tweetUrl });
// after
const page = await session.open(); // ensure logged-in browser session
await clis.twitter.like.func(page, { url: tweetUrl }); Defensive patterns
Strategy: validation
Validate before calling
if (!page) throw new Error('twitter like requires an open browser session — call session.open() first'); Type guard
function hasPage(p) { return p != null && typeof p === 'object' && typeof p.goto === 'function'; } Try / catch
try {
await clis.twitter.like.func(page, { url });
} catch (e) {
if (e.message.startsWith('Browser session required')) {
page = await session.open();
return clis.twitter.like.func(page, { url });
}
throw e;
} Prevention
- Always open/attach the browser session before invoking twitter commands
- In scripts, pass the page handle explicitly to command funcs
- Check the session is still alive (browser not closed/crashed) before each command
- Wrap long pipelines to re-open the session if it drops
When it happens
Trigger: Calling the `twitter like` command (or its exported func) without a connected browser session — i.e. `page` is null/undefined because no browser was launched or the session was not attached before invoking the command.
Common situations: Running the CLI outside a browser-session context (missing `--browser`/session attach flag or not calling the session-open command first); programmatically invoking the command's func with no page handle; the browser crashed or was closed earlier in a script so the page handle became null.
Related errors
- Browser session required for twitter hide-reply
- Browser session required for twitter unblock
- Browser session required for twitter unbookmark
- Browser session required for twitter unfollow
- 12306 whoami failed: ${probe.detail}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/248cda5a5069f565.
Report an issue: GitHub.