jackwener/OpenCLI · error · CommandExecutionError

Browser session required for twitter unlike

Error message

Browser session required for twitter unlike

What it means

The `twitter unlike` command is declared with `browser: true` and Strategy.UI, so its func expects a live, logged-in browser `page`. The registry passes `page` as the first argument; when no browser session exists (e.g. running outside an interactive/browser-backed context or the session failed to start), `page` is falsy and this CommandExecutionError is thrown before any navigation happens. Nothing was touched on x.com — it is a precondition failure.

Source

Thrown at clis/twitter/unlike.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: 'unlike',
    access: 'write',
    description: 'Remove a like from a specific tweet',
    domain: 'x.com',
    strategy: Strategy.UI,
    browser: true,
    args: [
        { name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the tweet to unlike' },
    ],
    columns: ['status', 'message'],
    func: async (page, kwargs) => {
        if (!page)
            throw new CommandExecutionError('Browser session required for twitter unlike');
        const target = parseTweetUrl(kwargs.url);
        await page.goto(target.url);
        await page.wait({ selector: '[data-testid="primaryColumn"]' });
        const result = await page.evaluate(`(async () => {
        let writeStarted = false;
        try {
            ${buildTwitterArticleScopeSource(target.id)}
            // Poll for the tweet to render. State probes scoped to the article
            // matching the requested status id — bare querySelector on a
            // conversation page would silently grab the first article (e.g.
            // the parent tweet) and unlike the wrong one.
            let attempts = 0;
            let likeBtn = null;
            let unlikeBtn = null;
            let targetArticle = null;

            while (attempts < 20) {
                targetArticle = findTargetArticle();

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Start a browser session first (ensure opencli launches/attaches its browser and you are logged into x.com), then re-run `opencli twitter unlike <tweet-url>`.
  2. If running in CI/headless, configure a browser-capable environment (install the browser and enable the browser strategy) instead of the default no-browser mode.
  3. Check that the browser did not crash before the call — restart the CLI process to rebuild the session.
  4. If embedding the registry, verify you pass a valid page/session to the command invocation rather than undefined.

Example fix

// before
opencli twitter unlike https://x.com/user/status/123  // no browser session -> error
// after
opencli browser start           # or open the interactive session first
opencli twitter unlike https://x.com/user/status/123
Defensive patterns

Strategy: validation

Validate before calling

// before invoking: ensure a browser-backed session exists
const page = await session.getPage(); // or registry-provided accessor
if (!page) {
  await startBrowserSession(); // launch/attach browser and log into x.com
}
return runCommand('twitter unlike', { url: tweetUrl });

Type guard

function hasBrowserPage(page) {
  return typeof page === 'object' && page !== null &&
    typeof page.goto === 'function' && typeof page.evaluate === 'function';
}

Try / catch

try {
  await cli.run(['twitter', 'unlike', tweetUrl]);
} catch (e) {
  if (/Browser session required/.test(e.message)) {
    await startBrowserSession();
    await cli.run(['twitter', 'unlike', tweetUrl]);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `opencli twitter unlike <url>` when the browser-backed session is unavailable: no browser launched/attached, running in a non-browser headless mode, or the browser process died and the registry passed `page === null/undefined` to func.

Common situations: Running the CLI in CI without a browser session; browser closed mid-session; invoking the command programmatically through the registry without initializing the browser; misconfigured opencli browser settings (e.g. missing browser binary or profile path).

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/22995f85d05d7088. Report an issue: GitHub.