{"record":{"id":"ecb3e083145fb80d","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-twitter-delete","errorCode":null,"errorMessage":"Browser session required for twitter delete","messagePattern":"Browser session required for twitter delete","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/delete.js","lineNumber":78,"sourceCode":"          return { ok: false, message: e.toString() };\n      }\n  })()`;\n}\ncli({\n    site: 'twitter',\n    name: 'delete',\n    access: 'write',\n    description: 'Delete a specific tweet by URL',\n    domain: 'x.com',\n    strategy: Strategy.UI, // Utilizes internal DOM flows for interaction\n    browser: true,\n    args: [\n        { name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the tweet to delete' },\n    ],\n    columns: ['status', 'message'],\n    func: async (page, kwargs) => {\n        if (!page)\n            throw new CommandExecutionError('Browser session required for twitter delete');\n        // parseTweetUrl throws ArgumentError on malformed/off-domain inputs —\n        // this replaces the ad-hoc local extractTweetId which only checked\n        // the path shape and accepted any host (silent: would try to act on\n        // attacker-controlled redirect URLs).\n        const target = parseTweetUrl(kwargs.url);\n        await page.goto(target.url);\n        await page.wait({ selector: '[data-testid=\"primaryColumn\"]' }); // Wait for tweet to load completely\n        const result = unwrapBrowserResult(await page.evaluate(buildDeleteScript(target.id)));\n        if (!result.ok) {\n            throw new CommandExecutionError(result.message, 'Nothing changed. Open the tweet in the browser and retry.');\n        }\n        await page.wait(2);\n        return [{\n                status: 'success',\n                message: result.message\n            }];\n    }\n});","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/delete.js#L60-L96","documentation":"The twitter delete command mutates state through a live, logged-in browser session. Its func receives page, and when no browser session exists (page is null) it throws this error rather than attempting to run the delete script in a nonexistent page.","triggerScenarios":"Invoking the twitter delete CLI command without an active browser session — e.g. not starting the browser beforehand, the session dying/closing before the command, or running in a context where browser automation was never initialized.","commonSituations":"Forgetting the browser start/login step in scripts; headless environment where the browser failed to launch; session timeout in long-running jobs; calling the command programmatically without passing a page.","solutions":["Start/log in to the browser session before running 'twitter delete' (per the CLI's browser-start command).","Verify the session is still alive if a long job ran between login and delete.","Re-run the command; if the browser crashed, restart it and reauthenticate.","Check headless/CI setup — ensure the browser binary is installed and launchable.","Catch the error in scripts and auto-start the browser, then retry the delete."],"exampleFix":"// before\nawait cliRun('twitter delete', { url: tweetUrl });\n// after\nif (!(await browserSessionActive())) {\n  await cliRun('browser open'); // start + log in first\n}\nawait cliRun('twitter delete', { url: tweetUrl });","handlingStrategy":"validation","validationCode":"if (!page) {\n  throw new Error('Start and log in to the browser session before running twitter delete');\n}","typeGuard":"function hasBrowserSession(page) {\n  return page != null && typeof page.goto === 'function' && typeof page.evaluate === 'function';\n}","tryCatchPattern":"try {\n  await cliRun('twitter delete', { url });\n} catch (err) {\n  if (/Browser session required/.test(err.message)) {\n    await startAndLoginBrowser();\n    await cliRun('twitter delete', { url });\n  } else throw err;\n}","preventionTips":["Always start + authenticate the browser before destructive twitter commands.","Check session liveness in long-running jobs before each mutation.","Ensure the browser binary is installed in headless/CI environments.","Wrap deletes with an auto-relogin retry on session errors.","Avoid running delete immediately after browser crashes without re-verifying the session."],"tags":["twitter","browser-session","authentication","prerequisite"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}