{"record":{"id":"616b1b99c265a4b5","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-twitter-accept","errorCode":null,"errorMessage":"Browser session required for twitter accept","messagePattern":"Browser session required for twitter accept","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/accept.js","lineNumber":19,"sourceCode":"import { CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\ncli({\n    site: 'twitter',\n    name: 'accept',\n    access: 'write',\n    description: 'Auto-accept DM requests containing specific keywords',\n    domain: 'x.com',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [\n        { name: 'query', type: 'string', required: true, positional: true, help: 'Keywords to match (comma-separated for OR, e.g. \"群,微信\")' },\n        { name: 'max', type: 'int', required: false, default: 20, help: 'Maximum number of requests to accept (default: 20)' },\n        { name: 'timeout', type: 'int', required: false, default: 600, help: 'Max seconds for the overall command (default: 600 — batch op)' },\n    ],\n    columns: ['index', 'status', 'user', 'message'],\n    func: async (page, kwargs) => {\n        if (!page)\n            throw new CommandExecutionError('Browser session required for twitter accept');\n        const keywords = kwargs.query.split(',').map((k) => k.trim()).filter(Boolean);\n        const maxAccepts = kwargs.max ?? 20;\n        const results = [];\n        let acceptCount = 0;\n        // Track already-visited conversations to avoid infinite loops\n        const visited = new Set();\n        for (let round = 0; round < maxAccepts + 50; round++) {\n            if (acceptCount >= maxAccepts)\n                break;\n            // Step 1: Navigate to DM requests page\n            await page.goto('https://x.com/messages/requests');\n            await page.wait(4);\n            // Step 2: Get conversations with scroll-to-load\n            const convInfo = await page.evaluate(`(async () => {\n        try {\n          // Wait for initial items\n          let attempts = 0;\n          while (attempts < 10) {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/accept.js#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the command through the normal CLI so a browser session is created (twitter login first if needed)","Ensure you are logged into x.com in the CLI's browser profile before running accept","If calling func programmatically, pass a valid Playwright Page object","Check earlier logs for browser-launch failures that left page undefined"],"exampleFix":"// before\nawait acceptCommand.func(null, { query: 'foo' });\n// after\nconst page = await openBrowserSession(); // established logged-in session\nawait acceptCommand.func(page, { query: 'foo' });","handlingStrategy":"validation","validationCode":"if (!page || typeof page.goto !== 'function') {\n  throw new Error('twitter accept requires an initialized browser page; run via the CLI');\n}","typeGuard":"function isBrowserPage(p) { return !!p && typeof p.goto === 'function' && typeof p.evaluate === 'function'; }","tryCatchPattern":"try {\n  await acceptCommand.func(page, kwargs);\n} catch (err) {\n  if (err.message.includes('Browser session required')) {\n    console.error('Launch the CLI so a logged-in browser session is created first');\n  } else throw err;\n}","preventionTips":["Always invoke the command through the CLI, not the raw func","Complete twitter login before batch operations","Check for browser-launch failures upstream that leave page undefined","In CI, provision a headless browser with a logged-in profile"],"tags":["browser","playwright","session"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}