jackwener/OpenCLI · error · CommandExecutionError

Browser session required for twitter hide-reply

Error message

Browser session required for twitter hide-reply

What it means

CommandExecutionError thrown by `twitter hide-reply` when it is invoked without a live browser page. Hiding a reply requires driving a real logged-in x.com session (page.evaluate on the tweet page); a null page means the command was run in a headless/API context with no browser session established.

Source

Thrown at clis/twitter/hide-reply.js:19

import { CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { parseTweetUrl, buildTwitterArticleScopeSource } from './shared.js';

cli({
    site: 'twitter',
    name: 'hide-reply',
    access: 'write',
    description: 'Hide a reply on your tweet (useful for hiding bot/spam replies)',
    domain: 'x.com',
    strategy: Strategy.UI,
    browser: true,
    args: [
        { name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the reply tweet to hide' },
    ],
    columns: ['status', 'message'],
    func: async (page, kwargs) => {
        if (!page)
            throw new CommandExecutionError('Browser session required for twitter hide-reply');
        const target = parseTweetUrl(kwargs.url);
        await page.goto(target.url);
        await page.wait({ selector: '[data-testid="primaryColumn"]' });
        const runHideAttempt = (allowParentDiscovery) => page.evaluate(`(async () => {
        try {
            ${buildTwitterArticleScopeSource(target.id)}
            const visible = (el) => !!el && (el.offsetParent !== null || el.getClientRects().length > 0);
            const moreLabels = new Set(['More', '更多']);
            const findParentConversationUrl = (targetArticle) => {
                const primary = document.querySelector('[data-testid="primaryColumn"]') || document;
                const articles = Array.from(primary.querySelectorAll('article'));
                const targetIndex = articles.indexOf(targetArticle);
                if (targetIndex <= 0) return null;
                for (let index = targetIndex - 1; index >= 0; index -= 1) {
                    const links = Array.from(articles[index].querySelectorAll('a[href*="/status/"]'))
                        .filter((link) => link.querySelector('time'));
                    for (const link of links) {
                        const statusId = __twGetStatusIdFromHref(link.href);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Start a browser session (e.g. `opencli open` or the session bootstrap your workflow uses) before running twitter hide-reply
  2. Re-run the command; if the session crashed, restart the CLI
  3. Ensure you are logged into x.com in that session, since hiding replies requires authenticated actions

Example fix

// before: no session
$ opencli twitter hide-reply https://x.com/user/status/123
Error: Browser session required for twitter hide-reply
// after: open a session first
$ opencli open https://x.com   # establishes the browser session
$ opencli twitter hide-reply https://x.com/user/status/123
Defensive patterns

Strategy: validation

Validate before calling

// Ensure a browser session exists before invoking hide-reply
const { execSync } = require('child_process');
try {
  execSync('opencli session status', { stdio: 'pipe' });
} catch {
  execSync('opencli open https://x.com'); // establish session
}

Type guard

function hasBrowserSession(ctx) {
  return !!ctx && !!ctx.page && typeof ctx.page.evaluate === 'function';
}

Try / catch

try {
  await cli.hideReply(url);
} catch (err) {
  if (/Browser session required/.test(err.message)) {
    await openSession('https://x.com');
    return cli.hideReply(url);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling the hide-reply command with no browser session: page is null at func entry, e.g. running outside the browser-backed mode or after the session failed to launch/closed.

Common situations: Running the command without starting the browser-backed CLI mode; the browser session crashed or was closed before the command; scripting the CLI programmatically without establishing a session first.

Related errors


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