{"record":{"id":"ab26fe23b21a27cf","repo":"jackwener/OpenCLI","slug":"error-ab26fe","errorCode":null,"errorMessage":"需要浏览器页面","messagePattern":"需要浏览器页面","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/wechat-channels/publish.js","lineNumber":577,"sourceCode":"  name: 'publish',\n  access: 'write',\n  description: '发布视频到视频号',\n  domain: 'channels.weixin.qq.com',\n  strategy: Strategy.COOKIE,\n  browser: true,\n  navigateBefore: false,\n  args: [\n    { name: 'video',    required: true,  positional: true, help: '视频文件路径 (.mp4/.mov/.avi/.webm)' },\n    { name: 'title',    required: false, help: '短标题（建议 6-16 字）' },\n    { name: 'caption',  required: false, help: '描述内容，支持直接写 #话题（如：日常生活 #搞笑 #生活）' },\n    { name: 'schedule', required: false, help: '定时发布时间（ISO8601 或 Unix 秒，如 \"2026-05-20 10:00\"）' },\n    { name: 'draft',    type: 'bool', default: false, help: '保存为草稿' },\n    { name: 'manual',   type: 'bool', default: false, help: '填完所有字段后不自动发布，由用户手动点击发表（务必同时传 --site-session persistent，否则表单页约 30 秒后会被重置为空白页）' },\n    { name: 'timeout',  type: 'int', required: false, default: 600, help: '命令整体超时秒数（含登录等待 + 上传转码，默认 600）' },\n  ],\n  columns: ['status', 'title', 'detail'],\n  func: async (page, kwargs) => {\n    if (!page) throw new CommandExecutionError('需要浏览器页面');\n\n    // ── 1. Validate inputs ───────────────────────────────────────────────\n    const timeoutSeconds = parseTimeoutSeconds(kwargs.timeout);\n    const deadline = Date.now() + timeoutSeconds * 1000;\n    const videoPath = requireFilePath(kwargs.video, '视频', VIDEO_EXTENSIONS);\n\n    const title = String(kwargs.title ?? '').trim();\n    const caption = String(kwargs.caption ?? '').trim();\n    const scheduleTime = parseScheduleDate(kwargs.schedule || null);\n    const isDraft = parseBooleanFlag(kwargs.draft);\n    const isManual = parseBooleanFlag(kwargs.manual);\n\n    // ── 2. Navigate to creator center ────────────────────────────────────\n    await page.goto(PUBLISH_URL);\n    await page.wait({ time: 4 }); // wujie needs extra time to bootstrap\n\n    // ── 3. Login check — fallback: navigate to login page and wait ───────\n    {","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wechat-channels/publish.js#L559-L595","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait cli.run('publish', { video: 'v.mp4' });\n// after\nawait cli.run('publish', { video: 'v.mp4', siteSession: 'persistent' });","handlingStrategy":"validation","validationCode":"if (typeof page === 'undefined' || !page) {\n  throw new Error('需要浏览器页面: run with a browser session (e.g. --site-session persistent)');\n}","typeGuard":"function hasBrowserPage(p) {\n  return !!p && typeof p.goto === 'function' && typeof p.evaluate === 'function';\n}","tryCatchPattern":"try {\n  await publishCmd(page, kwargs);\n} catch (e) {\n  if (e.message === '需要浏览器页面') {\n    console.error('No browser page: launch the command with a persistent site session.');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["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"],"tags":["wechat-channels","missing-page","browser-automation"],"backgroundTag":"missing-browser-page","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}