jackwener/OpenCLI · error · CommandExecutionError
Browser session required for twitter delete
Error message
Browser session required for twitter delete
What it means
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.
Source
Thrown at clis/twitter/delete.js:78
return { ok: false, message: e.toString() };
}
})()`;
}
cli({
site: 'twitter',
name: 'delete',
access: 'write',
description: 'Delete a specific tweet by URL',
domain: 'x.com',
strategy: Strategy.UI, // Utilizes internal DOM flows for interaction
browser: true,
args: [
{ name: 'url', type: 'string', required: true, positional: true, help: 'The URL of the tweet to delete' },
],
columns: ['status', 'message'],
func: async (page, kwargs) => {
if (!page)
throw new CommandExecutionError('Browser session required for twitter delete');
// parseTweetUrl throws ArgumentError on malformed/off-domain inputs —
// this replaces the ad-hoc local extractTweetId which only checked
// the path shape and accepted any host (silent: would try to act on
// attacker-controlled redirect URLs).
const target = parseTweetUrl(kwargs.url);
await page.goto(target.url);
await page.wait({ selector: '[data-testid="primaryColumn"]' }); // Wait for tweet to load completely
const result = unwrapBrowserResult(await page.evaluate(buildDeleteScript(target.id)));
if (!result.ok) {
throw new CommandExecutionError(result.message, 'Nothing changed. Open the tweet in the browser and retry.');
}
await page.wait(2);
return [{
status: 'success',
message: result.message
}];
}
});View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
await cliRun('twitter delete', { url: tweetUrl });
// after
if (!(await browserSessionActive())) {
await cliRun('browser open'); // start + log in first
}
await cliRun('twitter delete', { url: tweetUrl }); Defensive patterns
Strategy: validation
Validate before calling
if (!page) {
throw new Error('Start and log in to the browser session before running twitter delete');
} Type guard
function hasBrowserSession(page) {
return page != null && typeof page.goto === 'function' && typeof page.evaluate === 'function';
} Try / catch
try {
await cliRun('twitter delete', { url });
} catch (err) {
if (/Browser session required/.test(err.message)) {
await startAndLoginBrowser();
await cliRun('twitter delete', { url });
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 12306 whoami failed: ${probe.detail}
- Browser session required for bilibili summary
- Browser session required for twitter reply
- Browser session required for twitter retweet
- 12306 tk auth cookie missing
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ecb3e083145fb80d.
Report an issue: GitHub.