jackwener/OpenCLI · error · CommandExecutionError

Browser session required for twitter accept

Error message

Browser session required for twitter accept

What it means

The twitter accept command automates accepting follow/permission requests via a Playwright browser session. The func receives `page` and immediately throws CommandExecutionError when page is falsy, because the batch UI automation cannot run without a logged-in browser. This is a guard against calling the command's underlying function directly (e.g. programmatically) without an active session.

Source

Thrown at clis/twitter/accept.js:19

import { CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
cli({
    site: 'twitter',
    name: 'accept',
    access: 'write',
    description: 'Auto-accept DM requests containing specific keywords',
    domain: 'x.com',
    strategy: Strategy.UI,
    browser: true,
    args: [
        { name: 'query', type: 'string', required: true, positional: true, help: 'Keywords to match (comma-separated for OR, e.g. "群,微信")' },
        { name: 'max', type: 'int', required: false, default: 20, help: 'Maximum number of requests to accept (default: 20)' },
        { name: 'timeout', type: 'int', required: false, default: 600, help: 'Max seconds for the overall command (default: 600 — batch op)' },
    ],
    columns: ['index', 'status', 'user', 'message'],
    func: async (page, kwargs) => {
        if (!page)
            throw new CommandExecutionError('Browser session required for twitter accept');
        const keywords = kwargs.query.split(',').map((k) => k.trim()).filter(Boolean);
        const maxAccepts = kwargs.max ?? 20;
        const results = [];
        let acceptCount = 0;
        // Track already-visited conversations to avoid infinite loops
        const visited = new Set();
        for (let round = 0; round < maxAccepts + 50; round++) {
            if (acceptCount >= maxAccepts)
                break;
            // Step 1: Navigate to DM requests page
            await page.goto('https://x.com/messages/requests');
            await page.wait(4);
            // Step 2: Get conversations with scroll-to-load
            const convInfo = await page.evaluate(`(async () => {
        try {
          // Wait for initial items
          let attempts = 0;
          while (attempts < 10) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the command through the normal CLI so a browser session is created (twitter login first if needed)
  2. Ensure you are logged into x.com in the CLI's browser profile before running accept
  3. If calling func programmatically, pass a valid Playwright Page object
  4. Check earlier logs for browser-launch failures that left page undefined

Example fix

// before
await acceptCommand.func(null, { query: 'foo' });
// after
const page = await openBrowserSession(); // established logged-in session
await acceptCommand.func(page, { query: 'foo' });
Defensive patterns

Strategy: validation

Validate before calling

if (!page || typeof page.goto !== 'function') {
  throw new Error('twitter accept requires an initialized browser page; run via the CLI');
}

Type guard

function isBrowserPage(p) { return !!p && typeof p.goto === 'function' && typeof p.evaluate === 'function'; }

Try / catch

try {
  await acceptCommand.func(page, kwargs);
} catch (err) {
  if (err.message.includes('Browser session required')) {
    console.error('Launch the CLI so a logged-in browser session is created first');
  } else throw err;
}

Prevention

When it happens

Trigger: Calling the accept command's func with page === undefined/null — typically when invoking the exported function outside the normal CLI flow, or when the browser session failed to initialize before func ran.

Common situations: Scripting the command's func directly in tests or custom tools without spinning up a browser session; a headless environment where browser launch failed silently upstream.

Related errors


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