jackwener/OpenCLI · error · CommandExecutionError
需要浏览器页面
Error message
需要浏览器页面
What it means
The publish command's func requires a live browser page object; when it is null/undefined the command throws CommandExecutionError('需要浏览器页面'). This guards commands that must run inside an authenticated browser session.
Source
Thrown at clis/wechat-channels/publish.js:577
name: 'publish',
access: 'write',
description: '发布视频到视频号',
domain: 'channels.weixin.qq.com',
strategy: Strategy.COOKIE,
browser: true,
navigateBefore: false,
args: [
{ name: 'video', required: true, positional: true, help: '视频文件路径 (.mp4/.mov/.avi/.webm)' },
{ name: 'title', required: false, help: '短标题(建议 6-16 字)' },
{ name: 'caption', required: false, help: '描述内容,支持直接写 #话题(如:日常生活 #搞笑 #生活)' },
{ name: 'schedule', required: false, help: '定时发布时间(ISO8601 或 Unix 秒,如 "2026-05-20 10:00")' },
{ name: 'draft', type: 'bool', default: false, help: '保存为草稿' },
{ name: 'manual', type: 'bool', default: false, help: '填完所有字段后不自动发布,由用户手动点击发表(务必同时传 --site-session persistent,否则表单页约 30 秒后会被重置为空白页)' },
{ name: 'timeout', type: 'int', required: false, default: 600, help: '命令整体超时秒数(含登录等待 + 上传转码,默认 600)' },
],
columns: ['status', 'title', 'detail'],
func: async (page, kwargs) => {
if (!page) throw new CommandExecutionError('需要浏览器页面');
// ── 1. Validate inputs ───────────────────────────────────────────────
const timeoutSeconds = parseTimeoutSeconds(kwargs.timeout);
const deadline = Date.now() + timeoutSeconds * 1000;
const videoPath = requireFilePath(kwargs.video, '视频', VIDEO_EXTENSIONS);
const title = String(kwargs.title ?? '').trim();
const caption = String(kwargs.caption ?? '').trim();
const scheduleTime = parseScheduleDate(kwargs.schedule || null);
const isDraft = parseBooleanFlag(kwargs.draft);
const isManual = parseBooleanFlag(kwargs.manual);
// ── 2. Navigate to creator center ────────────────────────────────────
await page.goto(PUBLISH_URL);
await page.wait({ time: 4 }); // wujie needs extra time to bootstrap
// ── 3. Login check — fallback: navigate to login page and wait ───────
{View on GitHub (pinned to 49907e53dc)
Solutions
- Run the command with the browser/session flag (e.g. --site-session persistent) so a page is provided
- Check that the browser launched successfully before the command func runs
- When calling func programmatically, pass a real page object or mock
- Add an early check in the CLI wrapper to give a clearer message when page creation failed
Example fix
// before
await cli.run('publish', { video: 'v.mp4' });
// after
await cli.run('publish', { video: 'v.mp4', siteSession: 'persistent' }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof page === 'undefined' || !page) {
throw new Error('需要浏览器页面: run with a browser session (e.g. --site-session persistent)');
} Type guard
function hasBrowserPage(p) {
return !!p && typeof p.goto === 'function' && typeof p.evaluate === 'function';
} Try / catch
try {
await publishCmd(page, kwargs);
} catch (e) {
if (e.message === '需要浏览器页面') {
console.error('No browser page: launch the command with a persistent site session.');
process.exitCode = 2;
} else throw e;
} Prevention
- Always launch publish commands with the browser session flag
- Check browser launch success before invoking the command
- Guard programmatic calls with a page type guard
- Surface session-creation failures early in the CLI wrapper
When it happens
Trigger: Calling the publish command without a browser session, e.g. missing --site-session persistent / not launching the browser wrapper, or running the func programmatically without passing a page.
Common situations: Forgetting the session flag so no page is created; invoking the CLI function directly in tests without a page fixture; browser failed to launch upstream and page was passed as null.
Related errors
- 定时设置失败 (${reason}),截图: /tmp/wechat-channels_schedule_debug.p
- 找不到"${labels[0]}"按钮(按钮可能被禁用或表单未完成),截图已保存到 /tmp/wechat-channe
- 未能验证${isDraft ? '草稿保存' : '发布'}成功,截图已保存到 /tmp/wechat-channels
- Unexpected 12306 probe: ${JSON.stringify(probe)}
- Waiting for 12306 tk auth cookie
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/ab26fe23b21a27cf.
Report an issue: GitHub.