jackwener/OpenCLI · error · CommandExecutionError
Browser session required for weibo delete
Error message
Browser session required for weibo delete
What it means
The weibo delete command's func requires an authenticated browser page; the CLI framework injects it only when a browser session is active. If page is null/falsy, there is no browser to perform the in-page delete API call, so the command throws CommandExecutionError up front instead of failing later mid-flow.
Source
Thrown at clis/weibo/delete.js:61
cli({
site: 'weibo',
name: 'delete',
access: 'write',
description: 'Delete one of my Weibo posts by id',
domain: 'weibo.com',
strategy: Strategy.COOKIE,
args: [
{
name: 'id',
required: true,
positional: true,
help: 'Post ID (numeric idstr or mblogid from URL / weibo me / weibo post output)',
},
],
columns: ['status', 'id', 'mblogid'],
func: async (page, kwargs) => {
if (!page) {
throw new CommandExecutionError('Browser session required for weibo delete');
}
const raw = String(kwargs.id ?? '').trim();
const id = normalizePostId(raw);
await page.goto('https://weibo.com');
await page.wait(2);
const result = requireObjectEvaluateResult(unwrapEvaluateResult(await page.evaluate(`
(async () => {
const input = ${JSON.stringify(id)};
const readCookie = (name) => {
const pair = document.cookie.split(';').map(s => s.trim()).find(s => s.startsWith(name + '='));
return pair ? decodeURIComponent(pair.slice(name.length + 1)) : '';
};
// Step 1: resolve mblogid / idstr to canonical idstr via /show.
const showResp = await fetch('/ajax/statuses/show?id=' + encodeURIComponent(input), { credentials: 'include' });
if (showResp.status === 401 || showResp.status === 403) {
return { ok: false, error: 'auth', status: showResp.status };
}
// 404 from /show means the post does not exist (deleted, wrong id, orView on GitHub (pinned to 49907e53dc)
Solutions
- Run `weibo login` first to establish an authenticated browser session, then retry delete
- Check that the browser process/session from login is still alive; re-login if it crashed
- Persist/reuse the same browser profile directory so sessions survive across CLI invocations
- Ensure the automation environment (headful/headless config) allows the session browser to launch
Example fix
// before weibo delete --id 5012345678901 // no session // after weibo login weibo delete --id 5012345678901
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure a session exists before invoking delete
if (!await hasWeiboSession(page)) {
throw new Error('run `weibo login` before `weibo delete`');
} Type guard
function isMissingSessionError(err) {
return err instanceof CommandExecutionError && /Browser session required/.test(err.message);
} Try / catch
try {
await cliDelete({ id });
} catch (err) {
if (isMissingSessionError(err)) {
await cliLogin(); // establish browser session
await cliDelete({ id }); // retry once
} else throw err;
} Prevention
- Always run `weibo login` before session-scoped commands like delete
- Reuse a persistent browser profile so sessions survive across invocations
- Check session liveness (e.g. run `weibo me`) before destructive commands
- In CI, restore a pre-authenticated profile or perform login as a setup step
When it happens
Trigger: Running `weibo delete` without logging in first (no `weibo login`), a browser session that crashed or was closed before the command ran, or invoking the command through a script path that bypasses session setup.
Common situations: Fresh installs where login was never run, expired/crashed browser sessions between commands, running the command in CI without a logged-in browser profile, or headless environment misconfiguration that prevents the session from being restored.
Related errors
- Browser session required for bilibili subtitle
- Browser session required for bilibili summary
- Browser session required for bilibili unfollow
- Browser session required for bilibili video
- ChatGPT requires a logged-in browser session.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/0f32b2d045c899de.
Report an issue: GitHub.